Reputation: 105
sample react table will look like this
| show | name |
---------------------------
| *checkbox here* | test1 |
-------------------------
and the code for the setting of the columns is like this
const columns = [{
{title: 'Show', dataIndex: 'show',
render: value => {
let isCheck = (value == 'true');
return <Checkbox checked={isCheck} onChange={updateShow(*row id here*)}></Checkbox>
}
},
{title: 'Name', dataIndex: 'name'}
}];
and the table code is like this
<Table columns={columns} dataSource={*data from backend*}></Table>
I cant seem to get the row id since the data showing in the value is the data of that column and not the primary id of that row. Need some help im still a newbie with react.
Upvotes: 1
Views: 1621
Reputation: 841
If you are using ant design then render method gives you an access to 3 parameters, not only value selected with dataIndex
render: (value, row, index) => { ... }
Row should have all the data for a given entry, so probably it would be
render: (value, row) => {
let isCheck = (value == 'true');
return <Checkbox checked={isCheck} onChange={updateShow(row.id, isCheck)}></Checkbox>
}
},
Upvotes: 2