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, nodes that are not loaded are not filtered.
Parameters
value Object
(optional)
The filter configuration. Accepts the same values as the filter option.
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();
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(view.length);// displays 2
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(view[0].name); // displays "Jane Doe"
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(view[0].children.view().length); // displays 1
/* The result can be observed in the DevTools(F12) console of the browser. */
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();
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(filter.filters[0]); //displays '{field: "name", operator: "startswith", value: "John"}'
</script>