Server Filter using Contains for Child List

4 posts, 0 answers
  1. John
    John avatar
    4 posts
    Member since:
    Dec 2014

    Posted 22 Jul Link to this post

    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?
  2. Stefan
    Admin
    Stefan avatar
    276 posts

    Posted 26 Jul Link to this post

    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.
  3. Kendo UI is VS 2017 Ready
  4. John
    John avatar
    4 posts
    Member since:
    Dec 2014

    Posted 27 Jul in reply to Stefan Link to this post

    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

  5. Stefan
    Admin
    Stefan avatar
    276 posts

    Posted 29 Jul Link to this post

    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
Back to Top
Kendo UI is VS 2017 Ready