Hi,
I am developing a Kendo UI grid binding to ASP.NET MVC Web API controller. I have used the DataSourceRequestModelBinder class from the sample Web API Kendo project and the grid is working. Now I am attempting to add my own wildcard textbox field for filtering/searching the grid.
The following is the JS I have for doing this:
$('body').on("keyup click input", "#txtSearchCarGrid", function() {
var $filter = new Array();
var searchText = $("#txtSearchCarGrid").val();
if (searchText.length > 2) {
$filter.push({ field: "CarName", operator: "contains", value: searchText });
$filter.push({ field: "CustomerName", operator: "contains", value: searchText });
$filter.push({ field: "TankSize", operator: "contains", value: searchText });
$filter.push({ field: "MPG", operator: "contains", value: searchText });
} else {
return false;
}
return $("#CarGrid").data("kendoGrid").dataSource.filter({ logic: "or", filters: $filter });;
});
If I comment out the TankSize and MPG lines the filtering works as expected and I can search across the grid for CarName or CustomerName and the grid data will be filtered. The error I have having is with the TankSize which on my view model class is a int? field and MPG which is a double? field. When I include the lines in the js to search for them and start typing 60.0 which I know matches a number of MPG values on the grid data I get an error
An exception of type 'System.ArgumentException' occurred in Kendo.Mvc.dll but was not handled in user codeAdditional information: Provided expression should have string type
How can I fix this so I can search numeric fields across my WebAPI Binded grid in my js function?
I am developing a Kendo UI grid binding to ASP.NET MVC Web API controller. I have used the DataSourceRequestModelBinder class from the sample Web API Kendo project and the grid is working. Now I am attempting to add my own wildcard textbox field for filtering/searching the grid.
The following is the JS I have for doing this:
$('body').on("keyup click input", "#txtSearchCarGrid", function() {
var $filter = new Array();
var searchText = $("#txtSearchCarGrid").val();
if (searchText.length > 2) {
$filter.push({ field: "CarName", operator: "contains", value: searchText });
$filter.push({ field: "CustomerName", operator: "contains", value: searchText });
$filter.push({ field: "TankSize", operator: "contains", value: searchText });
$filter.push({ field: "MPG", operator: "contains", value: searchText });
} else {
return false;
}
return $("#CarGrid").data("kendoGrid").dataSource.filter({ logic: "or", filters: $filter });;
});
If I comment out the TankSize and MPG lines the filtering works as expected and I can search across the grid for CarName or CustomerName and the grid data will be filtered. The error I have having is with the TankSize which on my view model class is a int? field and MPG which is a double? field. When I include the lines in the js to search for them and start typing 60.0 which I know matches a number of MPG values on the grid data I get an error
An exception of type 'System.ArgumentException' occurred in Kendo.Mvc.dll but was not handled in user codeAdditional information: Provided expression should have string type
How can I fix this so I can search numeric fields across my WebAPI Binded grid in my js function?