sarojanand
sarojanand

Reputation: 607

iggrid filtering dynamically add filters on multiple columns (ignite-ui)

I want to apply filters on multiple iggrid columns based on URL parameters. Following code just show the last filter only. It ignores or overwrite what previous filter condition set.

  //value is multiple columns filter details separated by ;
  var columns = value.split(";")
  for (i = 0; i < columns.length; i++) {
   state_grid.igGridFiltering("filter", [{ fieldName: columns[i][0], expr: columns[i][2], cond: columns[i][1] }]);
  }

I was going thru this iggrid forum and found multiple filters can be applied like:

 $("#grid1").igGridFiltering("filter", [
 {fieldName: "MakeFlag", expr: true, cond: "true" , logic: "AND"},
 {fieldName: "ProductID", expr: 3, cond: "equals", logic: "OR"}
 ]);

If I hardcode the filter conditions, it works fine and filter text is shown on all columns. My question is how do I dynamically generate this in jQuery and pass it to igGridFiltering event. These conditions has to be loaded based on URL query strings. Can it be done like:

 var expression='';
 for (i = 0; i < columns.length; i++) {
    var vl = columns[i].split('_');
    expression += '{ fieldName:'+ vl[0]+', expr:'+ vl[2]+', cond:'+ vl[1]+' },';
 }
 state_grid.igGridFiltering("filter", [expression]);

Please help on this.

Upvotes: 1

Views: 2233

Answers (1)

sarojanand
sarojanand

Reputation: 607

Finally I found the answer with some tries. Basically I created a multi-dimensional array and passed it to the grid filtering event. The code is as below:

  var columns = value.split(";"), i, expression = [];

    for (i = 0; i < columns.length; i++) {
        var data = {},
            vl = columns[i].split('_');

        data.fieldName = vl[0];
        data.expr = vl[2];
        data.cond = vl[1];
        expression.push(data);
    }

    state_grid.igGridFiltering("filter", expression);

This code seems working without any issue. If anyone find any better solution, please let me know.

Thanks.

Upvotes: 1

Related Questions