Filter Grid as You Type
Environment
Product | Progress® Kendo UI® Grid for jQuery |
Operating System | All |
Browser | All |
Browser Version | All |
Description
How can I filter the Kendo UI Grid as I type?
Solution
Your project might require you to filter the Grid as the user types.
To achieve this behavior, provide for the following requirements:
- Enable the row filtering mode.
- Use a custom filter cell template for the desired Grid column.
- The purpose of the filter cell template is to attach a
data-value-update
attribute on theinput
event handler to the textbox (args.element
) which will trigger thechange
event of the textbox. Thechange
event will trigger the filtering functionality of the Grid. -
Change the default
"eq"
operator of the column with"contains"
,"startswith"
or any other supported operator.
The following example demonstrates how to filter the Grid on the fly, as the user types in the filter row textbox.
<div id="grid"></div>
<script>
$(function(){
$("#grid").kendoGrid({
dataSource: products,
filterable: {
mode: "row"
},
height: 400,
columns: [{
field: "ProductName",
title: "Product Name",
filterable: {
cell: {
operator: "contains",
template: function (args) {
args.element.css("width", "90%").addClass("k-textbox").attr("data-value-update", "input");
},
showOperators: false
}
}
}]
});
});
var products = new kendo.data.DataSource({
schema: {
model: {
id: "ProductID",
fields: {
ProductName: { type: "string" }
}
}
},
transport: {
read: {
url: "//demos.telerik.com/kendo-ui/service/products",
dataType: "jsonp"
}
}
});
</script>