Spread for ASP.NET 10 Product Documentation
Customizing Sorting of Rows of User Data

You can sort the data displayed in the sheet either by column or by row. Typically, all the rows of a sheet are sorted by the values in a particular column. But Spread allows various ways of performing a sort with various properties and methods for each type of sorting. In general, sorting data can be done by any of these ways:

There are various properties of sorting. The order of the sort can be in ascending order (A to Z, zero to 9) or descending order (Z to A, 9 to zero). The method of comparison can be customized. You can select which values to use as a key when comparing in order to sort the values. The sort indicator, an arrow typically, can be displayed in the header for the column being used as a sort key. For more information on customizing the sorting, refer to the SortInfo object. With this object, you can set the parameters for sorting and then specify this object in the particular sort method you choose.

The cell type does not matter for sorting. The sorting is done depending on the data type of the values in the cells. If you sort cells with data of the DateTime type, then it sorts those cells by date, and if you sort cells with data of the string type, it sorts those cells alphabetically.

You can sort entire rows or columns in a sheet. To sort all the rows of an entire sheet based on the values of a given column is the most common case, but Spread allows you to sort either rows or columns and to specify which column or row to use as a key for sorting. The sort applies to the entire sheet.

Use the SortColumns (or SortRows) method to sort the arrangement of columns (or rows) in a sheet using one or more rows (or columns) as the key. This does not affect the data model, only how the data is displayed. Several overloads provide different ways to sort the columns (or rows). To further customize the way sorting is performed, use the SortInfo object in conjunction with these methods.

Be aware of how sorting works with the data in the models. If you use the automatic sorting by clicking the column header or you call the SortRows method of the sheet, then the data model is not sorted, just the data that is displayed to the user. In this case, any data that is hidden before the sort is hidden after the sort, since Spread moves any hidden rows automatically. When you sort data, only the data model is getting sorted. The SelectionModel does not get sorted. For more information on the models, refer to Using Sheet Models.

Sorting executed by clicking column headers sorts only the displayed data and does not affect the order of actual data in the data model. So you can reset the sorted data being displayed to the order of actual data by calling either the ResetViewRowIndexes method or the ResetViewColumnIndexes method.

Also, sorting is not intended to be used when Outlook-style grouping is turned on. For more information about grouping (which is its own way a type of sorting), refer to Customizing Grouping of Rows of User Data.

Note: Cell spans become invisible when sorting a sheet.

You can allow the user to sort with the AllowSort property. See the following topic for more information:

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options | Documentation Feedback