admin管理员组文章数量:1024592
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"
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"
Share Improve this question edited Aug 12, 2015 at 15:32 TheDizzle asked Aug 12, 2015 at 13:38 TheDizzleTheDizzle 1,5745 gold badges35 silver badges81 bronze badges3 Answers
Reset to default 3A 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
orfalse
. - The operator for filtering should be "equals" not "contains" on a boolean field
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
});
});
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;
},
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"
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"
Share Improve this question edited Aug 12, 2015 at 15:32 TheDizzle asked Aug 12, 2015 at 13:38 TheDizzleTheDizzle 1,5745 gold badges35 silver badges81 bronze badges3 Answers
Reset to default 3A 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
orfalse
. - The operator for filtering should be "equals" not "contains" on a boolean field
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
});
});
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;
},
本文标签: javascriptKendo grid filter on boolean valuesStack Overflow
版权声明:本文标题:javascript - Kendo grid filter on boolean values - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745527436a2154590.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论