You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
More examples of how to configure sortable columns, including multi-column sorting and custom comparators, can be found in the <<../grid/index#sorting,Grid>> documentation.
144
144
====
145
145
146
-
In addition to column-level sorting, you can define a sort comparator directly on the `TreeDataProvider` instance using the `setSortComparator(SerializableComparator<T>)` method. This comparator is applied when no column sorting is used, and it acts as a secondary comparator if column sorting is used.
146
+
In addition to column-level sorting, you can define a sort comparator directly on the `TreeDataProvider` instance using the `setSortComparator(SerializableComparator<T>)` method. This comparator is applied when no column sorting is used, and it acts as a secondary comparator when combined with column sorting.
147
+
148
+
In the example below, a Select component is used to let users choose how folders are sorted in the Tree Grid. The `setSortComparator` method is called to apply the corresponding comparator based on the selected value:
147
149
148
150
[source,java]
149
151
----
150
-
// Set a custom sort comparator to sort folders by name in descending order.
151
-
// setSortComparator requires a Serializable comparator, so we use a lambda
152
-
// here since standard Comparator isn't serializable.
The `setSortComparator` method automatically re-renders the Tree Grid to reflect the new sort order.
163
-
164
-
Programmatically managing sorting can be useful when you have sort controls outside the Tree Grid and you want to integrate them.
173
+
The `setSortComparator` method re-renders the Tree Grid automatically, so calling `refreshAll` isn't necessary.
165
174
166
175
[NOTE]
167
176
====
168
-
To avoid breaking parent-child relationships, sorting only compares items within the same hierarchy level.
177
+
Sorting in tree structures is always performed independently at each level to avoid breaking the links between parents and their children.
169
178
====
170
179
171
180
=== Filtering Items
172
181
173
-
Tree Data Provider also supports in-memory filtering. To filter items, you can set a filter predicate on the [classname]`TreeDataProvider` instance using the [methodname]`setFilter(SerializablePredicate<T>)` method:
182
+
Tree Data Provider also supports in-memory filtering. You can apply filtering by setting a predicate via the `TreeDataProvider#setFilter(SerializablePredicate<T>)` method.
183
+
184
+
The following example demonstrates how this method can be used to filter folders based on a search term entered in a TextField component. As the user types, the Tree Grid updates in real time to show only folders whose names contain the search term:
174
185
175
186
[source,java]
176
187
----
177
-
// Only show folders whose names contain "doc" (case-insensitive)
The `setFilter` method automatically re-renders the Tree Grid to show the filtered results. When filtering, the Tree Data Provider evaluates the entire expanded hierarchy so that if a nested item matches, all its parents are included as well – even if they don't match the filter themselves.
198
+
The `setFilter` method re-renders the Tree Grid automatically, so calling `refreshAll` isn't necessary.
199
+
200
+
When filtering, the Tree Data Provider evaluates the entire expanded hierarchy. If a nested item matches the filter, all of its parent items are also included – even if they don't match the filter themselves – to ensure the matching item actually appears in the filtered tree.
0 commit comments