How to: Filter Data
- 2 minutes to read
The following example describes how to filter data within a Snap document 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 with this step skipped, you won’t be able to modify the document.
- Start modifying the list by calling the SnapEntity.BeginUpdate method.
- To apply filtering to the list, add the required string filter expression to the list collection of filter settings, accessible through SnapList.Filters property.
- Call the SnapEntity.EndUpdate method to finalize the list modification and 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
' Delete the document's content.
server.LoadDocument("Template.snx")
Dim list As SnapList = server.Document.FindListByName("Data Source 11")
server.Document.ParseField(list.Field)
list.BeginUpdate()
' Apply filtering:
Const filter As String = "[Discontinued] = False"
If Not list.Filters.Contains(filter) Then
list.Filters.Add(filter)
End If
list.EndUpdate()
list.Field.Update()