无法在React AG Grid中选择要删除的行

时间:2018-05-03 16:01:35

标签: ag-grid ag-grid-react

在React中,基于文档here,我尝试使用此代码选择要移除的AG网格行:

class MyComponent extends Component {
  constructor(props) {`
    this.state={rowSelection: 'single'}
  }

  onGridReady(params) {
    this.gridApi = params.api
    this.columnApi = params.columnApi
  }

  onRemoveSelected() {
    const selectedData = this.gridApi.getSelectedRows();
    const res = this.gridApi.updateRowData({ remove: selectedData })
  }
}

render() {
  return(
    <div>
      <button onClick={this.onRemoveSelected.bind(this)}>Remove Selected</button>
      <AgGridReact
        id="myGrid"
        {...gridOptions}
        onGridReady={this.onGridReady}
        rowSelection={this.state.rowSelection}
       />
      </div>
  )
}

但是这行没有选择。此外,使用代码的不同变体,有时我会收到此控制台警告:

cannot select node until id for node is known 

提前致谢

2 个答案:

答案 0 :(得分:1)

Ag-Grid Grid Properties Reference
Ag-Grid有一个名为gridOptions的道具,它带有一个对象。您可以从上面的参考资料中找到可以放入此对象的键,但是您要查找的键是getRowNodeId

示例(假设您的行数据包含名为id的键):

<AgGridReact
    gridOptions={{
        getRowNodeId : item => item.id
    }}
    {...gridOptions}
/>
...

答案 1 :(得分:0)

尝试遍历节点,并向每个节点添加一个ID。我不认为这是最理想的解决方案,但它确实有效。

system("curl --ntlm --user useid:password --upload-file C:/Users/Demo/1.html https://xxxx.sharepoint.com/sites/Test%20for%20upload/1.html")
相关问题