Adding a sort order programtically to a SalesLogix grid control

The SalesLogix grid view control found on quick forms and custom smart parts in SalesLogix is a custom control that is derived from the standard ASP.Net GridView control.  If you look at a deployed quick form you will see that the datasource is rendered to the ascx control markup as a method like this:

protected override void OnAddEntityBindings() {
       dsGrid0.Bindings.Add(new Sage.Platform.WebPortal.Binding.WebEntityListBinding(“Contacts”, grdAccountContacts ));
   dsGrid0.BindFieldNames = new String[] { “Id”,”LastName”,”FirstName”,”IsPrimary”,”WorkPhone”,”Title”,”Address.City”,”Address.State”,”Type”,”Department” };
     BindingSource.OnCurrentEntitySet += new EventHandler(dsGrid0_OnCurrentEntitySet);

 The data source control is named dsGrid0.  You can see then that it calls a method to bind the fields mentioned to the corresponding columns in the data grid.  The fields are bound in no default order and in order to create a default order you have two options:

1 Create a custom business rule that returns a collection of the entity to be bound with a sort definition added.  Then use the business rule as the binding source, rather than just simply binding to an entity collection

2 Utilize the SlxGridViewSortInfo class to define what the sort should be.  You can then add this code to the page load event (make sure not to run the code on each repaint or the grid can not be sorted by the user).

The SLXGridViewSortInfo has several overloads but the most useful one accepts to parameters, a sort order, and a string expression of the entity property you want to sort by.  This class is contained in the Sage.SalesLogix.Web.Controls namespace in the Sage.SalesLogix.Web.Controls.dll assembly.

To use it you simply do something like this:

Sage.SalesLogix.Web.Controls.SlxGridViewSortInfo s = new Sage.SalesLogix.Web.Controls.SlxGridViewSortInfo(System.Web.UI.WebControls.SortDirection.Ascending, “CreateDate”);

In this sample I am defining the sort to be based on the entity property “CreateDate”.

Then to actually sort a grid you just need to set the CurrentSortExpression to be = to the SLXGridViewSortInfo’s Expression result, like so:

 grdAccountContacts.CurrentSortExpression = s.Expression;

In this sample I am setting the SalesLogix grid named grdAccountContacts to have the sort based on my SLXGridViewSortInfo, aliased as s. 

Depending on the property in your sort condition, the grid will load with the column shown as sorted (if the property in the sort class is a column).  If the sort property is not a column it will still sort but you will see no visual representation that the grid has been sorted in any fashion.


Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!