Objective Grid : PART I User’s Guide : Chapter 5 Using Objective Grid : Sorting
Sorting
Objective Grid supports two types of sorting: a basic sort, and a more sensitive “natural” sort.
Basic Sorting
To support basic sorting when the user double-clicks the row header (col=0) or column header (row=0) use the following calls:
 
GetParam()->SetSortColsOnDblClk(TRUE); //sorting by ROWS
GetParam()->SetSortRowsOnDblClk(TRUE); //sorting by COLUMNS
By default, enabling sorting sets autodetect as the sorting method. Autodetect examines the data in the row or column and sets the sort type to numeric, alphanumeric, or datetime.
For more information on this type of sorting, see the following entries in the Objective Grid Class Reference:
CGXGridCore::SortRows
CGXGridCore::SortCols
CGXGridCore::ImplementGridSort
Natural Sorting
Natural sorting attempts to better reflect what a person would naturally expect the sort to do with respect to numeric values. For example, 10 miles, 1 kilometer, 2 feet, 100 inches, and 25 centimeters would be sorted as follows:
1 kilometer, 2 feet, 10 miles, 25 centimeters, 100 inches
Natural sorting takes place in your application's event handler, or when double-clicking the column's header if sorting of columns has been previously turned on and natural sorting specified. Natural sorting must be specified explicitly; that is, it is never set by autodetect.
 
// Add a sort info array in your CGXGridView-derived view class
CGXSortInfoArray m_sortInfo;
 
// Specify the natural sort type in your view class or event handler
m_sortInfo[0].sortType = CGXSortInfo::natural;
SortCols(CGXRange().SetTable(), m_sortInfo); // sort columns
SortRows(CGXRange().SetTable(), m_sortInfo); // sort rows
Sorting Example
Examples of both the basic and natural sorting implementations are demonstrated on the Sorting tab in the sample <stingray_installdir>\Samples\Grid\General\GridApp .
To test natural sorting in the GridApp sample:
1. Start the sample and go to the Sorting tab.
2. Click on any cell in columns B or C of the grid.
3. To use natural sorting on the selected column, from the Format | Sort Columns menu item click on the Natural option.
The column with focus should sort “naturally”.
Double-clicking either the column B or C header row also sorts the column, but autodetect sets a different sort type (numeric, alphnumeric, or datetime) rather than natural.