Skip to main content

Sorting Data

  • 3 minutes to read

The ExpressQuantumGrid provides you with the two following options to sort data in Grid Views:

  • by the column and card row content (available in tabular, Card, and Layout Views);

  • by group values or group summary values (available for grouped tabular Views only).

Both these options can be switched and customized with ease both at design time and runtime.

This topic describes the methods related to the first option. Refer to the Sorting Data by Group Summaries topic for more information on the second option.

Tabular Views represent data in columns, each of which has a caption displayed within the column header panel. An end-user can click on the column header to sort data by the column’s content. To sort by multiple columns, column headers should be clicked while holding down the Shift key. When data is sorted by a column, a small arrow is displayed in its caption indicating the current sort order. You can stop sorting against a particular column by clicking its header again while pressing the Ctrl key.

You may not want the user to be able to sort a particular View or column(s) - see the View’s OptionsCustomize.ItemSorting (OptionsCustomize.ColumnSorting in a grid Table View) or the item’s Options.Sorting properties.

When data is sorted by multiple columns, the order in which you apply sorting is important. Sorting orders the data according to the first sort column specified. Other column values only come into play if earlier column(s) data is identical.

Let us examine the Customers table from the CardsDB database. The following image shows a grid control with data sorted by the State, City and LastName columns. Data is sorted in descending order by the State column (and in ascending order by City and LastName). Filter arrows are indicated in color:

Sorting data programmatically can be applied to all types of items, i.e. columns in a grid Table View and rows in a Card View. To implement such sorting, you should use the item’s SortOrder property. Before sorting, you can call the View’s DataController.ClearSorting method to clear the current sorting if any. The following code sets sorting for the State, City and LastName columns specified by the tvCustomersState, tvCustomersCity and tvCustomersLastName objects respectively.

The tvCustomers object refers to the View containing these columns:

tvCustomers.BeginUpdate;
  tvCustomers.DataController.ClearSorting(True);
  tvCustomersState.SortOrder := soDescending;
  tvCustomersCity.SortOrder := soAscending;
  tvCustomersLastName.SortOrder := soAscending;
  tvCustomers.EndUpdate;

Note

The data controller uses multi-threaded algorithms to improve performance when sorting, filtering, or grouping data in “classic” data loading modes – when data-aware operations are performed on the client side, rather than on the server side (in server mode).

See Also