1
votes

I have a kendo grid that I've added a custom filter field to. The issue I'm running into is that my filter won't filter on the EEFinalize column. It filters fine on any column that has an actual word, but if it's a boolean true/false value it won't filter.

This is my search script

$(document).ready(function () {
        $("#FieldFilter").keyup(function () {

            var value = $("#FieldFilter").val();
            var grid = $("#grid").data("kendoGrid");

            if (value) {
                grid.dataSource.filter({
                    login: "or",
                    filters: [
                        { field: "ProfileName", operator: "contains", value: value },
                        { field: "EEFinalize", operator: "contains", value: value }
                    ]
                })
            } else {
                grid.dataSource.filter({});
            }
        });
    });

I also have converted the values of true/false to yes/no with clientTemplate.

columns.Bound(obcs => obcs.EEFinalize).ClientTemplate("#= EEFinalize ? 'Yes'
 : 'No' #").Title(FieldTranslation.GetLabel("EEFinalize", GlobalVariables.LanguageID));

I'm assuming the operator is probably incorrect but whatever I try it doesn't seem to filter anything. It runs the filter on the column but returns no values. All values in column are 'no' so it should display everything. In this case it filters it down to nothing.

If I select the grid filter icon it gives me options of "is true" and "is not true"

3

3 Answers

3
votes

A couple things wrong here and without seeing your columns or model I can't be sure.

  • Your logic property is misspelled.
  • If your EEFinalize field is setup as a boolean the value cannot be "no", it would be true or false.
  • The operator for filtering should be "equals" not "contains" on a boolean field
0
votes

First of all I'm assuming you declared your 'EFFinalize' field as 'boolean' in your schema model, otherwise it won't work. And your code should be like below:

$(document).ready(function () { $("#FieldFilter").keyup(function () {

        var value = $("#FieldFilter").val();
        var grid = $("#grid").data("kendoGrid");

        if (value) {
            grid.dataSource.filter({
                logic: "or",
                filters: [
                    { field: "ProfileName", operator: "contains", value: value },
                    { field: "EEFinalize", operator: "eq", value: value }
                ]
            })
        } 
       // don't do anything if 'value' does not exist
    });
});
0
votes

The only way I was able to achieve successful boolean filtering was to use the parse function on the datasource and explicitly set true or false values on the desired column.

parse: function(data) {
    if( undefined !== data.resources ) {
        for(var i=0; i < data.resources.length; i++ ) {
            if( data.resources[i]["IsChecked"] === "1" ) {
                data.resources[i]["IsChecked"] = true;
            } else {
                data.resources[i]["IsChecked"] = false;
            }
        }
    }
    return data;
},