搜索功能在kendo网格中无法正常工作

时间:2015-06-05 07:16:33

标签: kendo-ui

我有一个网格和搜索文本框。我点击它们后还有四个复选框,网格将过滤。但是,当我搜索任何元素时,我点击一个过滤器,整个网格数据正在显示。如何解决这个问题。?

2 个答案:

答案 0 :(得分:0)

 $("#search").keyup(function() {
     var selecteditem = $('#search').val();

     var kgrid = $("#grid").data("kendoGrid");


     selecteditem = selecteditem.toUpperCase();
     var selectedArray = selecteditem.split(" ");
     if (selecteditem) {
         kgrid.dataSource.filter({
             field: "MP.emp_first_name",
             operator: "eq",
             value: selecteditem
         }, {
             field: "MS.position_status",
             operator: "eq",
             value: selecteditem
         });


         var orfilter = {
             logic: "or",
             filters: []
         };
         var andfilter = {
             logic: "and",
             filters: []
         };

         $.each(selectedArray, function(i, v) {
             if (v.trim() == "") {} else {
                 $.each(selectedArray, function(i, v1) {
                     if (v1.trim() == "") {} else {
                         orfilter.filters.push({
                             field: "MP.emp_first_name",
                             operator: "contains",
                             value: v1
                         }, {
                             field: "MS.position_status",
                             operator: "contains",
                             value: v1
                         });

                         andfilter.filters.push(orfilter);
                         orfilter = {
                             logic: "or",
                             filters: []
                         };
                     }

                 });
             }
         });
         kgrid.dataSource.filter(andfilter);
         //    kgrid.dataSource.filter(orfilter);
     } else {
         kgrid.dataSource.filter({});
     }

 });




 $(".maf-filter").on('change', function(e) {
 var kgrid = $("#grid").data("kendoGrid");
 var andfilter = {
     logic: "and",
     filters: []
 };
 var orfilter = {
     logic: "or",
     filters: []
 };
 //alert($("#maf_filter_open").prop('checked'));
 if ($("#maf_filter_open").prop('checked')) {

     orfilter.filters.push({
         field: "MPOSSTATUS.position_status",
         operator: "eq",
         value: "ABC"
     });

 }

 if ($("#maf_filter_closed").prop('checked')) {
     orfilter.filters.push({
         field: "MPOSSTATUS.position_status",
         operator: "eq",
         value: "DEF"
     });

 }

 if ($("#maf_filter_cancelled").prop('checked')) {
     orfilter.filters.push({
         field: "MPOSSTATUS.position_status",
         operator: "eq",
         value: "GHI"
     });

 }

 if ($("#maf_filter_potential").prop('checked')) {
     orfilter.filters.push({
         field: "MPOSPOTENTIALCANDIDATE.emp_first_name",
         operator: "neq",
         value: ""
     }, {
         field: "MPOS.by_whom",
         operator: "neq",
         value: ""
     });

 }

 if (orfilter.filters.length > 0)
     andfilter.filters.push(orfilter);


 kgrid.dataSource.filter(andfilter);
 });
 //End- dynamic filtering



 }); //end of document ready

答案 1 :(得分:0)

<form role="form" class="form-inline">
<label><input type="checkbox" name="maf_filter_open" id="maf_filter_open" class="k-checkbox maf-filter" value="O" checked /> ABC</label>
<label><input type="checkbox" name="maf_filter_closed" id="maf_filter_closed" class="k-checkbox maf-filter" value="F" checked /> DEF</label>
<label><input type="checkbox" name="maf_filter_cancelled" id="maf_filter_cancelled" class="k-checkbox maf-filter" value="C"  checked />GHI </label>
<label><input type="checkbox" name="maf_filter_potential" id="maf_filter_potential" class="k-checkbox maf-filter" value="P" checked /> JKL</label>