Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add dynamic link to table data

Tags:

reactjs

antd

I'm working on a simple table using ReactJs and ant design, my problem is I don't know how to put value on the links using their data keys.

Thanks,

Codepen

SAMPLE CODE

const { Table } = antd;

const columns = [{
  title: 'Name',
  dataIndex: 'name',
  render: text => <a href="#">{text}</a>,
}, {
  title: 'Cash Assets',
  className: 'column-money',
  dataIndex: 'money',
}, {
  title: 'Address',
  dataIndex: 'address',
}];

const data = [{
  key: '1',
  name: 'John Brown',
  money: '¥300,000.00',
  address: 'New York No. 1 Lake Park',
}, {
  key: '2',
  name: 'Jim Green',
  money: '¥1,256,000.00',
  address: 'London No. 1 Lake Park',
}, {
  key: '3',
  name: 'Joe Black',
  money: '¥120,000.00',
  address: 'Sidney No. 1 Lake Park',
}];

ReactDOM.render(
  <Table
    columns={columns}
    dataSource={data}
    bordered
    title={() => 'Header'}
    footer={() => 'Footer'}
  />
, mountNode);
like image 408
Mark Gerryl Mirandilla Avatar asked Oct 16 '25 20:10

Mark Gerryl Mirandilla


1 Answers

Change this

render: text => <a href="#">{text}</a>

to this

render: (text, record) => <a href={'user/' + record.name}>{text}</a>

if you're using router

render: (text, record) => <Link to={'user/' + record.name}>{text}</Link>

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!