Search code examples
angulartypescriptag-gridag-grid-angular

How can I remove rows from a table? - "ag-grid"


I am using ag-grid library in my Angular project. I am trying to stop certain nodes from being displayed in the table through using doesExternalFilterPass to achieve that.

doesExternalFilterPass method runs for every node in the table and should not display it if the method returns false if I understand it correctly from their documentation:

doesExternalFilterPass is called once for each row node in the grid. If you return false, the node will be excluded from the final set.

Below is my code:

doesExternalFilterPass(node: any) {
    for(let i = 0; i < this.columnDefs.length; i++) {
        var temp = this.columnDefs[i].headerName;

        if(node.data[temp] === 'Declined') {
            console.log('found);
            return false;
        }
    }
}

The code runs successfully, and "found" is printed to the console. The above code removes the value 'Declined' from the Filter List of the column but the rows that has the value 'Declined' are still shown in the table.

How can I completely remove the rows with 'Declined' value?

your guidance will be appreciated.


Solution

  • Sounds to me that you would want to filter out those objects from your data before even displaying it in the grid, so a simple filter would do if I am not misunderstanding your question:

    this.myData = this.myData.filter(obj => obj.someProperty !== "Declined");
    
    // then create the grid
    

    Obviously change the variable and property names to yours.