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

Kendo Grid - Server Filtering with Multiple columns

1 Answer 871 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ebony
Top achievements
Rank 1
Ebony asked on 25 May 2016, 02:46 PM

I copied this from a post in made in 2012.  This is exactly what is happening in my application.  Any pointers on how to get around it?  Everything works fine until I try to filter on more than one column. 

I am trying to implement server side filtering using the Kendo UI Grid and ASP .NET Web API RC.  It works fine with one column, but when the user filters on a second column issues occur.  The values for the second column seem to be included in the array of values for column one.  How can I parse this on the server?

I am including the JSON format of the data being passed to the server because it is easier to read.  Normally I have to pass the values in the query string.  If the JSON format could be used that would be better (so let me know if anyone knows how):

{"take":10,"skip":0,"page":1,"pageSize":10,"filter":{"filters":[{"field":"Column1","operator":"eq","value":"val1"},{"field":"Column1","operator":"eq","value":"val2"},{"logic":"or","filters":[{"field":"Column2","operator":"eq","value":5},{"field":"Column2","operator":"eq","value":1}]}],"logic":"and"},"group":[]}

Here are the c# objects for the mapping that I found online that currently only works with one column.  PageListArguments is the object that is used as the input parameter for the Get function of the Web API Controller.

    public class GridFilter
    {
        public string Field { get; set; }
        public string Operator { get; set; }
        public string Value { get; set; }
    }

    public class GridFilters
    {
        public List<GridFilter> Filters { get; set; }
        public string Logic { get; set; }
    }

    public class GridSort
    {
        public string Field { get; set; }
        public string Dir { get; set; }
    }

    public class PageListArguments
    {
        public int Take { get; set; }
        public int Skip { get; set; }
        public int Page { get; set; }
        public int PageSize { get; set; }
        public string Group { get; set; }
        public List<GridSort> Sort { get; set; }
        public GridFilters Filter { get; set; }
    }

Everything parses fine except for the filter when more than one column is used.

1 Answer, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 27 May 2016, 09:13 AM

Hello Ebony,

I have already answered in Ticket ID: 1037717, but I will also post here, so others might benefit as well:

Please check out the following how-to article from our documentation:

http://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/web-api-server-operations

... or the WebApi Grid demo from the sample application, available with your installation package.

Note that a special model binder for the request has to be used:

public DataSourceResult Get([System.Web.Http.ModelBinding.ModelBinder(typeof(WebApiDataSourceRequestModelBinder))]DataSourceRequest request)
{
    return service.Read().ToDataSourceResult(request);
}

I hope this helps, but if applying the necessary adjustments to your implementation does not solve the problem, please send us an isolated runnable project, demonstrating the issue, so we can investigate it further.

Regards,
Dimiter Topalov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Ebony
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Share this question
or