I am providing tree formatted data to the grid. When I used the in column filters, it applies the filters to the leaf nodes and shows parent nodes where needed to provide a path to the leafs.
I am looking for a way to allow the user to provide a quick filter along with the column filters. The quick filter would filter out all non-leaf nodes that do not contain the filter text. End result would be that the user could filter out non-leaf nodes with the quick filter, then filter down to leaf nodes with the column filter.
Any ideas how to accomplish this? I realize I could filter the tree data and pass it pre-filtered to the grid, but I really need to find a way to implement this while still passing the entire unfiltered tree data to the grid.
Is this possible? If not, could I somehow hide a non-leaf node manually without removing it from the tree data model?
Perhaps you have seen this enhancement request on github...
https://github.com/ceolter/ag-grid/issues/110
I took the example that was created there and modified it with an externalFilter
. Here is a JSFiddle as an example.
Here's the process for the external filter:
When an input is changed, inform the grid by calling gridOptions.api.onFilterChanged()
Let the grid know that an external filter is present by setting gridOptions.isExternalFilterPresent
to true
gridOptions.doesExternalFilterPass
will then be called on each node
- It is important to note that it is called on each node... a group isn't considered a node, only the leaf elements
Each node contains data for it's parent via node.parent
, so check the parent's group name if it contains the filter text, in the example this looks like: node.parent.data.group.includes($scope.filter)
which if true then that node will remain in the grid.
This example only shows one level deep... if you have groups within groups, then the logic in doesExternalFilterPass
will get more complicated by being recursive in checking the parent's parent's name, but that logic shouldn't be too terrible...
Also, if you have any groups that don't have children, they will automatically be filtered out since they don't really have nodes to display/be filtered on.