Skip to content
Advertisement

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?

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement