"Quickening the Pace of JSP Development" Friday, September 10, 2010
Home Products Pricing Company Contact Us Samples Download Forums Javadoc Customers
    « Form Tags »
    « I/O Tags »
    « Format Tags »
    « Utility Tags »
Grid Control Taglib - Custom Sorting Example

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).

Messages
 
Id Last Name First Name Gender Zip
 
10 Danns Allan Male 04105
  2 adas asdasdad Female 34561
  6 Obama barack Female 04101
  18 Obama Barrack Jr. Female 32419
  13 Fellows Bill Male 04105
  12 Test Data Male 78723
  3 das dsad Female 22151
  9 Leno Jay Male 04105
  7 Hogan jeff Male 04105
  19 Gatezngan Jeff Male 10234
  15 Chan Liam Male 47387
  14 Lu Lucy Female 42844
  4 Gbv matt Male 90210
  16 McCartney Paul Male 78378
  11 ppp Paula Female 04106
  8 gcg prova Male 66778
  1 test Ryan Male 112312313
  20 Ruthi Vijay Male 4354
  5 Jackson xxx11111 Female 1234

The above grid contains 19 records.

  Download Raw Data     Download Formatted Data
 CustomSortAction.java     MyGridListenerCustomSort.java   



          Back to Samples page


home : products : pricing : company : contact us : samples : download : forums : customers

Copyright © 2000-2004 dotJ Software Inc. All rights reserved.