How To Filter Grid Rows That Do Not Contain Value

2 posts, 0 answers
  1. kirelet
    kirelet avatar
    5 posts
    Member since:
    Sep 2013

    Posted 10 Jan 2014 Link to this post

    Using "contains" filter gives me all rows that do not have the specified value.  How can I filter grid rows that do not contain a certain value, so that I only get rows that do have the value?  I tried "doesnotcontain" which doesn't work.

    if (val) {
                    grid.dataSource.filter({
                        logic: "or",
                        filters: [
                        { field: "someField", operator: "contains", value: val },
                       { field: "someField2", operator: "contains", value: val },
    ...
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1441 posts

    Posted 14 Jan 2014 Link to this post

    Hello AJ,

    The contains operator filters out all items that does not contain the specified value, leaving only the ones that do. For example:  
    //Let say this is our data:
    data: [
        {field1: "abc", field2: "a"},
        {field1: "abc", field2: "b"},
        {field1: "cde", field2: "c"},
        {field1: "cde", field2: "d"},
        {field1: "edf", field2: "e"},
        {field1: "edf", field2: "f"}
    ],
     
     
    //Using this filter
    dataSource.filter({
        logic: "or",
        filters: [
        { field: "field1", operator: "contains", value: "a" },
        { field: "field2", operator: "contains", value: "a" }
        ]});
     
    //Wil display the following items:
    {field1: "abc", field2: "a"},
    {field1: "abc", field2: "b"},
     
     
    //Using AND logic however, will narrow down the results even further
    dataSource.filter({
        logic: "and",
        filters: [
        { field: "field1", operator: "contains", value: "a" },
        { field: "field2", operator: "contains", value: "a" }
        ]});
         
    //And the grid will display only one item:
    {field1: "abc", field2: "a"},


    Regards,
    Alexander Popov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top