This is a migrated thread and some comments may be shown as answers.

Wilcard Filter in Web API Binded Grid

1 Answer 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Tomas asked on 25 Jun 2014, 08:35 AM
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?

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 27 Jun 2014, 07:34 AM
Hello Tomas,

We are not sure how to replicate this behavior. Hover if `TankSize` and `MPG` are expected to be numbers you should convert them in the filter expressions as well. For example:
$filter.push({ field: "TankSize", operator: "contains", value: Number(searchText) });
$filter.push({ field: "MPG", operator: "contains", value: Number(searchText) });


Regards,
Nikolay Rusev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Tomas
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or