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

Filter by multiple values

1 Answer 242 Views
Grid for HTML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Zac
Top achievements
Rank 1
Zac asked on 20 Jun 2013, 02:49 AM
I want to filter a column by multiple values
e.g.
grid.dataSource.filter = { field: "ID", operator: "eq", value: [1,4] };
which should return any rows where ID = 1 OR ID = 4.

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Yankov
Telerik team
answered on 20 Jun 2013, 07:28 AM
Hi Zac,

The DataSource filter property takes an array of filter expressions like the one you used, except the filter value must match the value of the filtered field. In your case the "ID" field is probably a single number and it does not equal an array of numbers. Each filter expression must be set as a separate JavaScript object in an array:

grid.dataSource.filter = [
    { field: "ID", operator: "eq", value: 1 },
    { field: "ID", operator: "eq", value: 4 }
];

The default filter logic operator is "and". If you want to change the logic operator, you will have to set the logic option of the filter property to "or" and assign the filter array to the filters option:

grid.dataSource.filter = {
    logic: "or",
    filters: [
        { field: "ID", operator: "eq", value: 1 },
        { field: "ID", operator: "eq", value: 4 }
    ]
};

I hope this helps. Let me know if you need any further assistance.

Regards,
Martin Yankov
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Grid for HTML
Asked by
Zac
Top achievements
Rank 1
Answers by
Martin Yankov
Telerik team
Share this question
or