Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant Design - prevent table row click in specific column/area

Tags:

antd

I'm using ant design table component. I have "actions" column that I don't want the onRowClick event will trigger in this column.

How can it be done?

http://codepen.io/liron_e/pen/zZjVKZ?editors=001

const { Table, Modal } = antd;

const confirm = (id) => {
  Modal.confirm({
    title: 'Confirm',
    content: 'Bla bla ...',
    okText: 'OK',
    cancelText: 'Cancel',
  });
};

const info = (id) => {
  Modal.info({
    title: 'Info',
    content: 'Bla bla ...',
    okText: 'OK',
    cancelText: 'Cancel',
  });
};

const columns = [
  {
    key: 'status',
    title: 'text',
    dataIndex: 'text'
  }, {
    key: 'actions',
    title: 'actions',
    dataIndex: 'id',
    render: (id) => {
      return (
        <span>
          <a href="#" onClick={() => confirm(id)}>
            Clone
          </a>
          <span className="ant-divider" />
          <a href="#" onClick={() => confirm(id)}>
            Replace
          </a>
        </span>
      );
    }
  }
];

 const dataSource = [
   {
     id: '1',
     text: 'Hello'
   },{
     id: '123',
     text: 'adsaddas'
   },{
     id: '123344',
     text: 'cvbbcvb'
   },{
     id: '5665',
     text: 'aasddasd'
   },
 ];


ReactDOM.render(
  <div>
    <Table 
      columns={columns}
      onRowClick={() => this.info()}
      dataSource={dataSource}
    />
  </div>
, mountNode);

As you can try when pressing on row the info modal would open. When pressing some action the info and the confirm modals would open, and I would like that only confirm modal would open.

Thanks (:

like image 235
lironer Avatar asked Mar 23 '17 16:03

lironer


People also ask

How do you make an ant design table responsive?

You can make use of the responsive property on the column that you want to control for screen sizes. Just add a From To column with a custom render function, and set the responsive property on that column to only show on xs screens. The From and To columns will have the responsive property set to show on md and above.

How do I select a row in ANTD table?

Rows can be selectable by making first column as a selectable column. You can use rowSelection.type to set selection type. Default is checkbox . selection happens when clicking checkbox by default.

How do I hide columns in ANTD table?

Add a property "hidden" to the column object, then filter it out. Save this answer.

How do I sort in ANTD table?

Adding the sorting functionality in the table is very easy. We just have to use the sorter prop one of the column props provided to us by the Antd, which when used in any column gives us the ability to sort the data of that column alphanumerically.


1 Answers

In your render function:

render: (id) => {
  return (
    <span>
      <a href="#" onClick={(e) => { 
           e.stopPropagation();      
           confirm(id);
          }}>
        Clone
      </a>
      <span className="ant-divider" />
      <a href="#" onClick={() => confirm(id)}>
        Replace
      </a>
    </span>
  );
}
like image 152
Marcos Gin Avatar answered Sep 29 '22 01:09

Marcos Gin