Articles in this section
Category / Section

How to sort the data in UWP SfSpreadsheet ?

3 mins read

SfSpreadsheet provides support to sort a range of cells in the workbook based on data.

Sorting can be done based on cell values, font color and cell color respectively. For more info, please go through XlsIO UG link

 

For sorting process,

  • Create a data sorter of workbook in SfSpreadsheet.
  • Set a sorting range to sort the data in the IRange of the worksheet.
  • Set the sort order and type of sort to be performed in the selected range by using ISortField interface.
  • Then the sorting operation can be done by invoking the Sort method of IDataSort interface.
  • Finally invalidate the cells to refresh the view in SpreadsheetGrid.

 

The following code illustrates how to perform the sorting operation in SfSpreadsheet

 

C#

 
IDataSort sorter = this.spreadsheet.Workbook.CreateDataSorter();
 
//To sort a range of cells,
sorter.SortRange = this.spreadsheet.ActiveSheet.Range["E3:E8"];
sorter.HasHeader = false;
ISortField sortField = sorter.SortFields.Add(4, SortOn.Values,OrderBy.Ascending);
sorter.Sort();
sorter.SortFields.Remove(sortField);
spreadsheet.ActiveGrid.InvalidateCell(GridRangeInfo.Cells(2,5,8,6), true);
 
// To sort a particular column
sorter.SortRange = this.spreadsheet.ActiveSheet. Range["C3:C12"];
sorter.HasHeader = false;
ISortField sortField = sorter.SortFields.Add(2, SortOn.Values,OrderBy.Descending);
sorter.Sort();
sorter.SortFields.Remove(sortField);
spreadsheet.ActiveGrid.InvalidateCell(GridRangeInfo.Col(2), true);
 

 

Sample links: 

 

WPF

 

WinRT

 

WinForms

 

UWP


Conclusion

I hope you enjoyed learning about how to sort the data in UWP SfSpreadsheet.

You can refer to our UWP SfSpreadsheet.feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied