New to Kendo UI for jQuery? Download free 30-day trial

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 the input event handler to the textbox (args.element) which will trigger the change event of the textbox. The change 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>

See Also

In this article