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

Filter parse exception when using ge, le or ne option

3 Answers 363 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robyn
Top achievements
Rank 1
Robyn asked on 23 Mar 2015, 10:44 PM
The below Url's requests work and return data.

http://localhost:63455/api/data/gethistory?$top=5&$filter=(Id+eq+1+and+PaymentId+eq+11)
http://localhost:63455/api/data/gethistory?$top=5&$filter=(Id+eq+1+and+PaymentId+gt+11)
http://localhost:63455/api/data/gethistory?$top=5&$filter=(Id+eq+1+and+PaymentId+lt+11)

The below Url requests do not work and return an exception. This is Greater than or Equal to, Less that or Equal To and Not Equal to

http://localhost:63455/api/data/gethistory?$top=5&$filter=(Id+eq+1+and+PaymentId+ge+11)
http://localhost:63455/api/data/gethistory?$top=5&$filter=(Id+eq+1+and+PaymentId+le+11)
http://localhost:63455/api/data/gethistory?$top=5&$filter=(Id+eq+1+and+PaymentId+ne+11)

I am using a kendo grid with server filtering turned on and the grid calls a data source which is a web API controller that accepts a custom Model binder (by implementing IModelBinder) and on that model binder, it does the below which fails. 

var filter = "(TransportProviderId eq 1 and PaymentRequestId ge 5)"
request.Filters = FilterDescriptorFactory.Create(string.Join("~", filter.Split(' ')));


{"Message":"An error has occurred.","ExceptionMessage":"Expected RightParenthesis","ExceptionType":"Kendo.Mvc.Infrastructure.Implementation.FilterParserException","StackTrace":" at Kendo.Mvc.Infrastructure.Implementation.FilterParser.Expect(FilterTokenType tokenType)\r\n at Kendo.Mvc.Infrastructure.Implementation.FilterParser.ParseNestedExpression()\r\n at Kendo.Mvc.Infrastructure.Implementation.FilterParser.PrimaryExpression()\r\n at Kendo.Mvc.Infrastructure.Implementation.FilterParser.ComparisonExpression()\r\n at Kendo.Mvc.Infrastructure.Implementation.FilterParser.AndExpression()\r\n at Kendo.Mvc.Infrastructure.Implementation.FilterParser.OrExpression()\r\n at Kendo.Mvc.Infrastructure.Implementation.FilterParser.Expression()\r\n at Kendo.Mvc.Infrastructure.Implementation.FilterParser.Parse()\r\n<br>at Kendo.Mvc.Infrastructure.FilterDescriptorFactory.Create(String input)\r\n at RequestModelBinder.BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 25 Mar 2015, 03:10 PM
Hello Robyn,

How can we reproduce the issue? The offline demo project that we have regarding WebAPI does not seems to throw such exceptions:

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/webapi-editing

http://screencast.com/t/1VjKmbFkcDl

Please demonstrate your case so we can investigate what causes this.

Kind Regards,
Petur Subev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Robyn
Top achievements
Rank 1
answered on 25 Mar 2015, 09:06 PM
Hi Petur Subev,

To give you more context, we are actually not using WebApiDataSourceRequestModelBinder. We have written our own Custom binder since we have turned on Server side filtering. The parse failure is in the FilterDescriptorFactory.Create call within the custom binder, when we try to create request.Filters. Please note that this is part of Kendo.Mvc.Infrastructure. Please also note that _dataProvider.History returns Odata result.

WebAPI Controller Method
public DataSourceResult GetHistory([ModelBinder(typeof(CustomRequestModelBinder))] DataSourceRequest request)
{
  IQueryable<HistoryOData> payments = _dataProvider.History.OrderByDescending(p => p.DueDate);
  var results = payments.ToDataSourceResult(request);
  return results;
}


Custom Model Binder
public class CustomRequestModelBinder : IModelBinder
{  
     public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
     {
       DataSourceRequest request = new DataSourceRequest();
       string sort, filter;
       int pageStart, pageSize;           
 
       if (TryGetValue(bindingContext, "$filter", out filter))
       {   
         request.Filters = FilterDescriptorFactory.Create(string.Join("~", filter.Split(' ')));
       }
 
       bindingContext.Model = request;
 
       return true;
     }       
}


Kendo grid config

self.gridConfig = {
        data: undefined,
        autoBind: false,
        serverFiltering: true,       
        dataSource: new kendo.data.DataSource({
            type: "odata",
            serverFiltering: true,
            pageSize: 5,
            serverPaging: true,
            serverSorting: true,
            transport: {
                read: {
                    url: "/api/payments/gethistory",
                    dataType: "json",
                },
                parameterMap: function (options, type) {
                    var paramMap = kendo.data.transports.odata.parameterMap(options);
                    delete paramMap.$inlinecount;
                    delete paramMap.$format;
 
                    return paramMap;
                }
            },
        filterable: true,
        sortable: true,
        pageable: true
.....
    };
0
Petur Subev
Telerik team
answered on 27 Mar 2015, 02:13 PM
Hello Robyn,

I understand that you are using the Kendo Infrastructure to implement your scenarios, however please keep in mind the methods that you are using are not documented and are intended for internal usage and we do not guarantee their behavior when invoked manually neither we support them.

Nevertheless if you demonstrate your case with a small stand-alone demo we can have a look and probably get a clue what might be going wrong. Thank you for the understanding.

Kind Regards,
Petur Subev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Robyn
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Robyn
Top achievements
Rank 1
Share this question
or