Filter parse exception when using ge, le or ne option

4 posts, 0 answers
  1. Robyn
    Robyn avatar
    2 posts
    Member since:
    Jun 2014

    Posted 23 Mar 2015 Link to this post

    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)
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 25 Mar 2015 Link to this post

    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.

     
  3. Robyn
    Robyn avatar
    2 posts
    Member since:
    Jun 2014

    Posted 25 Mar 2015 in reply to Petur Subev Link to this post

    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
    .....
        };
  4. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 27 Mar 2015 Link to this post

    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.

     
Back to Top