Sorting data

You can sort the data in any DataSet subclass, including the QueryDataSet, ProcedureDataSet (Client/Server version only), TableDataSet, and DataSetView components. When sorting data in JBuilder, note that:

Sorting data in a GridControl

If your application includes a GridControl that is associated with a DataSet, you can sort on a single column in the grid by clicking the column header in the running application. Click again to toggle from ascending to descending order. You can disable this feature by setting the sortOnHeaderClick property of the GridControl to false.

Sorting data using the JBuilder visual design tools

If you need your application to sort in a specified order, the JBuilder visual design tools allow you to quickly set these properties. The sort property editor dialog provides an easy way to

This example describes how to sort a data set in ascending order by last name. To set sort properties using the JBuilder visual design tools:

  1. Open or create the project you created for "Providing data".
  2. Select the QueryDataSet in the Component tree. Click the Design tab.
  3. In the Inspector, double-click the area beside the sort property. This displays the sort property editor.
  4. Specify values for options that affect the sort order of the data. In this case, select the LAST_NAME field from the list of Available Columns, click Add To Sort. The dialog will look like this:

  5. Click the OK button.

    The property values you specify in this dialog are stored in a SortDescriptor object.

  6. Select Run|Run to compile and run the application. It will look like this:

Sorting data in code

You can enter the code manually or use JBuilder design tools to generate the code for you to instantiate a SortDescriptor. The code generated automatically by the JBuilder design tools looks like the following:


queryDataSet1.setSort(new borland.jbcl.dataset.SortDescriptor(

new String[] {"EMP_NO", "LAST_NAME", "FIRST_NAME" }, true, false));

In this code segment, the SortDescriptor is instantiated with sort column of employee number (EMP_NO), then the last and first names (LAST_NAME and FIRST_NAME), case insensitive, and in ascending order.