How can I add/remove rows in ag-Grid?

I've using ag-Grid with my React - Typescript project I can set data and get selected data from table but I don't know how to add new empty field and how to remove selected field, I've find on its documents but does not found :(

Upvotes: 1

Views: 4519

Answers (1)

Using setRowData to set rows so when I want to add new empty field I have to do like

const allNodesData = Array<any>()
this.gridApi.forEachNode((node) => {
  allNodesData.push(node.data)
})
allNodesData.push({})
this.gridApi.setRowData(allNodesData)

And when I want to remove selected field I have to do like

const selectedNodes = this.gridApi.getSelectedNodes()
const allNodesData = Array<any>()
this.gridApi.forEachNode((node) => {
  if (selectedNodes.indexOf(node) < 0)
    allNodesData.push(node.data)
})
this.gridApi.setRowData(allNodesData)

Upvotes: 2

Related Questions