How to: Sort Data
The following example demonstrates how to sort Snap document data using the following steps.
- Load the document template using the RichEditDocumentServer.LoadDocumentTemplate method.
- Call the ISnapFieldOwner.CreateSnList method to create a new Snap list or retrieve one of the existing lists by calling the ISnapFieldOwner.FindListByName method.
- Convert the document fields to Snap Fields. To do that, call the ISnapFieldOwner.ParseField method. Note that without performing this step, you won’t be able to modify the document.
- Enable modifying the list by calling the SnapEntity.BeginUpdate method.
- Create a new sorting parameter represented by the SnapListGroupParam instance. Pass the target field name and the desired sort order to the SnapListGroupParam object’s constructor method.
- Add the created object to the corresponding list collection. To do that, access the collection through the SnapList.Sorting property and call the Add method.
- Call the SnapEntity.EndUpdate method to finalize the list modification. Then, update the list fields by calling the FieldCollection.Update method.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/snap-document-server-api-t429162
server.LoadDocumentTemplate("Template.snx")
Dim list As SnapList = server.Document.FindListByName("Data Source 11")
server.Document.ParseField(list.Field)
list.BeginUpdate()
list.Sorting.Add(New SnapListGroupParam("UnitPrice", ColumnSortOrder.Descending))
list.EndUpdate()
list.Field.Update()