Guerrilla
Guerrilla

Reputation: 14876

ag-Grid row not deleting

I am trying to delete a row from my ag-Grid like so:

let alertRow : RowNode = this.gridApi.getRowNode(rowIndex);
console.log(alertRow);
this.gridApi.updateRowData({remove: [alertRow]});

It gives me this error:

ag-Grid: could not find data item as object was not found

I can see in console the RowNode is the correct node and exists. I am also able to use updateRowData() to add new rows in fine but trying to remove gives this error.

I am using ag-Grid in Angular 6 component.

Why is removing not working?

Upvotes: 11

Views: 16044

Answers (3)

user7396942
user7396942

Reputation:

If you use vue.js, you can use this lines of codes:

  1. Get select row, const selectedRow = this.gridApi.getFocusedCell()

  2. Get node by select row const node = this.gridApi.getRowNode(selectedRow.rowIndex)

  3. ApplyTransaction to remove the node by data of the node. this.gridApi.applyTransaction({ remove: [node.data] })

Upvotes: 2

Gregg L
Gregg L

Reputation: 380

Not entirely sure this is the right place/way to add on to un.spike's answer, but if you're using the getSelectedNodes method to obtain the data you're trying to delete, the syntax is a little different (requires indexing into the selected node).

(Both assume you're using single row selection)

getSelectedNodes

const selectedNode = this.gridApi.getSelectedNodes();
this.gridApi.updateRowData({ remove: [selectedNode[0].data] });

And, for "completeness" sake,
getSelectedRows (even though the API suggests using getSelectedNodes)

const selectedRow = this.gridApi.getSelectedRows();
this.gridApi.updateRowData({ remove: selectedRow });

Upvotes: 1

un.spike
un.spike

Reputation: 5113

Replace updateRowData({remove:[alerRow]}) by

updateRowData({remove:[alertRow.data]}))

updated doc

... If you are not using ID's, then the grid will match the rows based on object reference.

Upvotes: 19

Related Questions