Search code examples
javascripthtmlreactjsantd

How to reset ant design table selected rows?


  • I am using ant design table component and I have selected rows.
  • I want onClick reset selected rows.
  • I can not find out where it stores selected rows.

      const rowSelection = {
            onChange: (selectedRowKeys, rows) => {
              this.setState({
                selectedRowsArray: [...rows]
              });
            },
          };
    
      <Table rowSelection={rowSelection} columns={columns} dataSource={paymentsHistory} />
    

Any Idea how to clear selected rows?


Solution

  • rowSelection also takes selectedRowKeys property that will help you control the selected rows at any point in time.

    const { selectedRowsArray } = this.state;
    const rowSelection = {
          selectedRowKeys: selectedRowsArray,
          onChange: (selectedRowKeys, rows) => {
            this.setState({
              selectedRowsArray: [...rows]
            });
          },
        };
    
    <Table rowSelection={rowSelection} columns={columns} dataSource={paymentsHistory} />
    

    Codesandbox Example | Antd Docs