Skip to content

v1.12.0

Compare
Choose a tag to compare
@cheton cheton released this 28 Jul 08:00
· 94 commits to master since this release

Improvements

How to filter nodes?

In your row renderer, returns undefined or an empty string to filter out unwanted nodes (i.e. node.state.filtered === false):

import tag from 'html5-tag';

const renderer = (node, treeOptions) => {
    if (node.state.filtered === false) {
        return;
    }

    // Do something

    return tag('div', treeNodeAttributes, treeNode);
};

The filter function accepts a keyword string, or a function to test each node of the tree. The function returns true to keep the node, false otherwise.

Filter by string
const keyword = 'text-to-filter';
const filterOptions = {
    caseSensitive: false,
    exactMatch: false,
    filterPath: 'props.name', // Defaults to 'name'
    includeAncestors: true,
    includeDescendants: true
};
tree.filter(keyword, filterOptions);
Filter by function
const keyword = 'text-to-filter';
const filterOptions = {
    includeAncestors: true,
    includeDescendants: true
};
tree.filter(function(node) {
    const name = node.name || '';
    return name.toLowerCase().indexOf(keyword) >= 0;
});
Turn off filter

Calls tree.unfilter() to turn off filter.

tree.unfilter();