Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular5: Hide ag-gird rows based on condition

I have the below response from the service, when ever the flag is true I have to hide the whole row (total 20 columns I have) else show it. How can I achieve this in ag-grid?

data = {
    name: "A",
    flag: true
   },
   {
    name: "B",
    flag: false
   },
   {
    name: "C",
    flag: false
   }

I did try the useExternalFilter like below and then I got stuck as to how to use this useExternalFilter further. Can any one please guide me through.

this.filterOptions = {
  useExternalFilter: true
};

this.gridOptions = {
  filterOptions:  this.filterOptions
 };
like image 719
Anna Avatar asked Oct 21 '25 15:10

Anna


2 Answers

what you want is this:

this.gridOptions = {
  // is always present, so return true
  isExternalFilterPresent: function() { 
    return true; 
  },

  // return true if flag=true
  doesExternalFilterPass: function(rowNode) { 
    return rowNode.data.flag; 
  }
};

see ag-Grid Docs for more details

like image 142
Niall Crosby Avatar answered Oct 23 '25 04:10

Niall Crosby


Simplest way to do this is, filter your data first based on the flag value

const filteredData = this.data.filter(item => !item.flag);

Then set this filteredData as grid data

this.gridOptions.setRowData(this.filteredData);

Hope this will do the needful

like image 42
Dilani Alwis Avatar answered Oct 23 '25 04:10

Dilani Alwis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!