-
Notifications
You must be signed in to change notification settings - Fork 12
TreeGrid Datasource Refactoring
The current tree grid implementation is married to the idea that the source is a flat list of rows with a parent/child relationship defined in the data using a parentId property. This translates poorly to a situation where the contents of any parent are fetched asynchronously.
A tree grid requires three components:
- TreeGrid extension, that takes care of the view side of things (expand/collapse toggles...)
- TreeGridDataSource, which transforms the tree into a flat structure, taking into consideration which treenodes are expanded or collapsed: two flavors -- SyncTreeGridDataSource which is focused on performance with in-memory treesources, and assumes the given treesource does not return any Promises -- AsyncTreeGridDataSource which is aimed at asynchronous treesources, but sacrifices performance and some functionality.
- TreeSource, which represents the hierarchical data
The TreeSource is the interface between the actual data source and the TreeGridDataSource. If necessary, this TreeSource needs to be aware of sorting and filtering. It needs to communicate changes to its data through events to the TreeGridDataSource.
It has the following methods:
- isReady(): boolean // returns true when the methods below are safe to be called
- getRecordCount(): (number|Promise) // returns the total number of rows in the grid (optional)
- getRootNodes(start?: number, end?: number): (any[]|Promise<any[]>) // returns the root nodes within the start->end window if specified
- hasChildren(parent: any) // returns whether the given node has children
- children(parent: any, start?: number, end?: number): (any[]|Promise<any[]>) // returns child nodes within the start->end window if specified
- countChildren(parent: any): (number|Promise) // returns the number of children in the given node
- countRootNodes(): (number|Promise); // returns the number of root nodes
- filter(settings: object, predicate: function) // tells the treesource to apply the filter and trigger any data change events. Keep in mind that if a child matches the filter, its ancestors should match the filter also in order to be shown in the results. (optional, only required if filtering is enabled on the grid)
- sort(comparator: function, settings: object) // tells the treesource to apply the sorting and trigger any data change events (optional, only required if sorting is enabled on the grid)
- getStatistics(): object // return the grid statistics
- getRecordById(id: any): any // return the record with the given id; this id will already have been known so retrieve from a cache (no Promise return value allowed here)
It can emit the following events:
- dataloaded // when the data is changed or loaded
The DefaultTreeSource is the TreeSource that turns a flat list of records with a parentId property into hierarchical data. It takes a DataSource as a delegate to retrieve this flat list of records, and builds an internal tree structure based on the input data. It also responds to data changes in the delegate appropriately, so that the internal tree structure is kept up to date.
This is a wrapper for asynchronous treesources that takes care of all caching. The underlying treesource can safely issue requests for any calls it receives.