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
As before, make sure to call [methodname]`TreeDataProvider#refreshAll()` to update the Tree Grid UI after making any structural changes to the [classname]`TreeData`.
131
131
132
+
=== Sorting Items
133
+
134
+
Tree Data Provider provides built-in support for in-memory sorting. You can enable sorting on Tree Grid columns, and the data provider will automatically sort the items based on the sort order selected by the user:
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
+
====
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 will be applied by default and will run after any column-level comparators:
147
+
148
+
[source,java]
149
+
----
150
+
// setSortComparator requires a serializable comparator, so
151
+
// we use a lambda since Comparator itself isn't serializable.
Sorting is always applied independently at each hierarchy level to preserve the tree structure.
157
+
132
158
== Custom Data Providers
133
159
134
160
Conceptually, any hierarchical data provider, including [classname]`TreeDataProvider`, is a class that implements the [classname]`HierarchicalDataProvider` interface.
135
161
136
-
For convenience, Flow provides a related abstract base class [classname]`AbstractHierarchicalDataProvider`, which you can extend to create a custom hierarchical data providers. This class requires implementing the following methods:
162
+
For convenience, Flow provides a related abstract base class [classname]`AbstractHierarchicalDataProvider`, which you can extend to create a custom hierarchical data provider. This class requires implementing the following methods:
137
163
138
164
[source,java]
139
165
----
140
-
class CustomDataProvider extends AbstractHierarchicalDataProvider<T, F> {
166
+
public class CustomDataProvider extends AbstractHierarchicalDataProvider<T, F> {
141
167
@Override
142
168
public boolean isInMemory() { // <1>
143
169
// Your implementation here
@@ -194,7 +220,7 @@ Below is an example of a simple in-memory data provider using the nested hierarc
194
220
[source,java]
195
221
.FolderDataProvider.java
196
222
----
197
-
class FolderDataProvider implements AbstractHierarchicalDataProvider<Folder, Void> {
223
+
public class FolderDataProvider implements AbstractHierarchicalDataProvider<Folder, Void> {
198
224
public FolderTreeData folderTreeData = new FolderTreeData();
199
225
200
226
@Override
@@ -298,7 +324,7 @@ Below is an example of a simple in-memory data provider using the flattened hier
298
324
[source,java]
299
325
.FolderDataProvider.java
300
326
----
301
-
class FolderDataProvider implements AbstractHierarchicalDataProvider<Folder, Void> {
327
+
public class FolderDataProvider implements AbstractHierarchicalDataProvider<Folder, Void> {
302
328
public FolderTreeData folderTreeData = new FolderTreeData();
0 commit comments