While all connector can sort data by url manipulation, only Grid and TreeGrid has native GUI for sorting, so below info most actual for those two components.
To make grid sort content with connectors you need to use “connector” as sorting type while grid initialization. For example:
myGrid.setColSorting("connector,str,na");
Here the first column will be sorted on server with connectors, the second as string on client side, the third column will not be sortable.
If you need to customize the way of sorting you can use “BeforeSelect” server side event. Event doesn't allow to write custom sorting logic , but you can affect SORT BY clause generation. Current collection of sorting rules might be accessed by using DataRequest object which may be found in every connector.
Define default sorting
connector.BeforeSelect += new EventHandler(connector_BeforeSelect); void connector_BeforeSelect(object sender, EventArgs e) { this.Connector.Request.OrderBy.Add( new OrderByField(this.Connector.Request.RequestedFields[0], "DESC") //ORDER BY first selected field by descending order no matter what field is ); }
alternatively we can rewrite this example like:
connector.BeforeSelect += new EventHandler(connector_BeforeSelect); void connector_BeforeSelect(object sender, EventArgs e) { this.Connector.Request.OrderBy.Add( new OrderByField((TableField)"PrintableName", "DESC") //ORDER BY "PrintableName" field by descending order ); }
or even:
connector.BeforeSelect += new EventHandler(connector_BeforeSelect); void connector_BeforeSelect(object sender, EventArgs e) { this.Connector.Request.OrderBy.Add(new OrderByExpression("PrintableName DESC"));//ORDER BY "PrintableName" expression }
All three examples will cause the same effect. OrderBy collection is collection of OrderByStatement objects. OrderByStatement itself is an abstract class, but it has 2 descendants: OrderByField and OrderByExpression. OrderByField allows you to specify field object you want to order by and it's direction. Field can be taken from Request.RequestedFields collection of created right on the spot. OrderByExpression allows you to specify ready to use SQL statement that will be inserted directly into ORDER BY sql statement.
OrderByExpression usage
connector.BeforeSelect += new EventHandler(connector_BeforeSelect); void connector_BeforeSelect(object sender, EventArgs e) { this.Connector.Request.OrderBy.Add( new OrderByExpression("DATEPART(yy, Person.CreatedDate) DESC") //ORDER BY CreatedDate's year. ); }