filter multiple id's in javascript

Questionsfilter multiple id's in javascript
Glenn asked 9 years ago

Hi Abu,

I can filter a single id. Is it possible to filter an array of id's.
eg. array("10016","12345","22222")

The below works for single id.
var myfilter = { groupOp: "AND", rules: []};
myfilter.rules.push({field: "id", op: "cn", data: "10016"});
var myGrid = $("#list_master").jqGrid();
myGrid[0].p.search = myfilter.rules.length>0;
$.extend(myGrid[0].p.postData,{filters:JSON.stringify(myfilter)});
myGrid.trigger("reloadGrid",[{page:1}]);
myGrid.setSelection("10016, true);

if I add another element it does not work
myfilter.rules.push({field: "id", op: "cn", data: "22222"});

Thanks
Glenn

2 Answers
Abu Ghufran answered 9 years ago

You can use 'in' operator and comma sep vales.
myfilter.rules.push({field: "id", op: "in", data: "10016,12345,22222"});

Glenn answered 9 years ago

Thanks Abu,

That worked perfectly.
Your the best.

Glenn

Your Answer

18 + 0 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?