Edit this page

filter

Gets or sets the filter configuration. It applies the filter to all loaded nodes and creates views from the nodes that match the filter and their parent nodes up to the root of the hierarchy. Currently not loaded nodes are not filtered.

Parameters

value Object (optional)

The filter configuration. Accepts the same values as the filter option (check there for more examples).

Returns

Object the current filter configuration. Returns undefined if the DataSource instance has not performed filtering so far.

Example - set the data source filter

<script>
        var dataSource = new kendo.data.HierarchicalDataSource({
            change: function(e) {
             for (var i = 0; i < e.items.length; i++) {
                e.items[i].load();
             }
            },
            data: [
            { name: "Jane Doe", items: [
                { name: "Jane Doe" },
                { name: "John Doe" }
            ] },
            { name: "John Doe" }
            ]
        });

        dataSource.fetch();
        dataSource.filter({ field: "name", operator: "startswith", value: "John" });
        var view = dataSource.view();

        console.log(view.length);// displays 2
        console.log(view[0].name); // displays "Jane Doe"
        console.log(view[0].children.view().length); // displays 1
        console.log(view[0].children.view()[0].name); // displays "John Doe"
</script>

Example - get the data source filter

<script>
    var dataSource = new kendo.data.HierarchicalDataSource({
        filter: { field: "name", operator: "startswith", value: "John" },
        change: function(e) {
             for (var i = 0; i < e.items.length; i++) {
                e.items[i].load();
             }
        },
        data: [
        { name: "Jane Doe", items: [
            { name: "Jane Doe" },
            { name: "John Doe" }
        ] },
        { name: "John Doe" }
        ]
    });

    dataSource.fetch();
    var filter = dataSource.filter();

    console.log(filter.filters[0]); //displays '{field: "name", operator: "startswith", value: "John"}'
</script>
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy