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

How To Filter Grid Rows That Do Not Contain Value

1 Answer 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kirelet
Top achievements
Rank 2
kirelet asked on 10 Jan 2014, 08:36 PM

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 },
...

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 14 Jan 2014, 11:45 AM
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!
Tags
Grid
Asked by
kirelet
Top achievements
Rank 2
Answers by
Alexander Popov
Telerik team
Share this question
or