Spread ASP.NET supports several different methods of sorting. Sorting occurs on the server side. You can sort the data displayed in the sheet either by column or by row. Sorting data makes it easier to find information. Spread has the following sort methods:
- Sort
- SortColumns
- SortRows
The order of the sort can be in ascending order (A to Z, 0 to 9) or descending order (Z to A, 9 to 0). You can customize the comparison method and you can select which values to use as a comparison key when sorting. Use the SortInfo object in the Sort method to customize sorting. You can sort entire rows or columns in a sheet and you can specify which column or row to use as a key for sorting. Use the SortColumns (or SortRows) method to sort the 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 sorting, use the SortInfo object with these methods. You can double-click the column header to sort if you set the AllowSort property to true. The sort indicator (an arrow by default) is displayed in the column header after sorting. The cell type does not matter for sorting. The sorting is based on the data type of the values in the cells. If you sort cells with the DateTime type, then it sorts those cells by date, and if you sort cells with the string type, it sorts those cells alphabetically. 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 using either the ResetViewRowIndexes method or the ResetViewColumnIndexes method. You can use the GetModelRowFromViewRow and GetModelColumnFromViewColumn methods to get the model coordinates after sorting. The following example sets the AllowSort property. Double-click the column header to sort. AllowSort C#
VB
This example creates a Column object for the sheet, sets text in the first three rows of the column, and sorts the column data using a button click event. The sort indicator for the column is displayed after the column is sorted. C#
VB
This example sorts a range of columns and specifies a sort key. Use this method if you want to specify more than one row by which to sort (have more than one key for sorting). The SortInfo array can contain multiple keys (multiple rows) and the first specified row is the primary key. C#
VB
You can also sort on the client-side with the SortColumn method. This method causes a postback to occur. The AllowSort property must be set to True for the sheet. This example sorts the column. JavaScript
C#
VB
The SortColumnCommand event occurs when AllowSort is True. This example uses the SortColumnCommand event and returns the sorted column. C#
VB