Search All Columns in KendoUI Grid

后端 未结 3 755
谎友^
谎友^ 2020-12-31 04:02

I am trying to create a search box for a kendoUI grid. I have been able to get a start on doing a search based on one field however I would like the value in my search box t

3条回答
  •  执笔经年
    2020-12-31 04:22

    If you don't want to have to worry about column names you can use this code instead. It will work on any grid and will search all columns that are marked as filterable without specifying hard coded column names. Also, I added additional events so that if someone were to copy and paste a search query the event would be called. (This also requires jQuery 1.83 or higher). I created this code after I switched from jQuery Datatables plugin to Kendo UI Grid. I love Kendo but really missed the global search textbox offered by DataTables. I include this code on all my Kendo Grids.

         $("#category").on("keypress blur change", function () {
            var filter = { logic: "or", filters: [] };
            $searchValue = $(this).val();
            if ($searchValue) {
                $.each($("#grid").data("kendoGrid").columns, function( key, column ) {
                    if(column.filterable) { 
                        filter.filters.push({ field: column.field, operator:"contains", value:$searchValue});
                    }
                });
            }
            $("#grid").data("kendoGrid").dataSource.query({ filter: filter });
        });
    

提交回复
热议问题