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

Server Filter using Contains for Child List

3 Answers 725 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 22 Jul 2016, 11:11 AM
I am trying to filter on a value in a child array of an object using server side filtering 

I have an object like:

public class person{
     public int id {get; set;}
 public List<int> accountIdList {get; set;}    <br>
}


On a grid I generate a custom filter template which allows a user to filter by Accounts (e.g a dropdown list of accounts).  
The datasourcerequest object on the server is populated with a filter.  I want to be able to intercept the filter and change the filter from an equals
to a contains

I've done the following

private DataSourceRequest InterceptRequest(DataSourceRequest request)
        {
            for (int idx = 0; idx < request.Filters; idx++)
            {
                var flt = filterList[idx] as FilterDescriptor;
                if (flt != null && flt.Member.ToString().Equals("accountIdList"))
                {
                    flt.Operator = FilterOperator.Contains;
                    flt.Value = 1;   //Hardcode as an example
                }
            }
        }

However when I call ToDataSourceResult I get an error stating an invalid cast from Int32 to IEnumerable<Int32>

I want to get a list of all persons who have an Account Id of 1.  How can I achieve this?

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 26 Jul 2016, 12:46 PM
Hello John,

If I understand correctly, the desired result is to change the filter operator from equals to contains? This can be achieved via custom binding:

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/binding/custom-binding

Please have in mind that the contains operator can filter only string values:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-filter.operator

Additionally, if the end result is to get a list of all persons who have an Account Id of 1, the equals operator is better options than contains.

In order to assist you further, could please send a runnable example and provide additional information for the used scenario.

Regards,
Stefan
Telerik by Progress
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
0
John
Top achievements
Rank 1
answered on 27 Jul 2016, 01:12 PM

Hi Stefan,

It is an integer that I will need to filter on.   The child array will be an array of integers.  For example accountIdList  may contain the values (1,2,3,4).  From the front end I would pass in a value of 1 so I need some way of checking if the value 1 is in the accountIdList.

Contains seemed the logical way for me but you have stated that this only works for strings so this won't work

0
Stefan
Telerik team
answered on 29 Jul 2016, 12:16 PM
Hello John,

Thank you for the additional information.

I can confirm that this can be achieved only with custom binding. Please have in mind that in this case all of the operations like paging, filtering, sorting and grouping have to be implemented manually.

Let me know if you need additional information about the Kendo UI DataSource API.

Regards,
Stefan
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Data Source
Asked by
John
Top achievements
Rank 1
Answers by
Stefan
Telerik team
John
Top achievements
Rank 1
Share this question
or