Sorting is one critical item when it comes to using grids to display your data. By default, our library can sort the rows
of a grid using a generic algorithm. This suffices for most basic needs. However, sometimes you may wish to perform the
row sorting on your own and just have the grid render accordingly.
This is now possible in version 2.0 by way of the IGridCommandEventArgs and IGridListener interfaces.
In this example, we let the database do the row sorting using the standard ORDER BY SQL clause. The sort parameters
are posted to the server and can be extracted out via the IGridCommandEventArgs interface. The sort parameters
can then be translated into SQL. The last part is to inform the grid that the rows are already sorted. This can be done
using the doCustomSort callback method.
public boolean doCustomSort(ISortContext sortContext) {
// Tell the grid we are sorting upon the first display of the grid.
if (isPost == false) {
sortContext.setSortColumnNumber(sortColumn);
sortContext.setSortType(sortType);
}
return true;
}
By returning true, you are telling the grid not to sort the rows. In the above example, the two setter calls
are necessary since we are showing the grid as sorted when it first displays (isPost == false).