I am using react-bootstrap-table2
, to make tables, I have encounter an issue i.e
I want o have a checkbox inside my table, so I am following This, mention in the documentation, but I am getting unexpected result.
My code
For selecting the row
JavaScript
x
6
1
const selectRow = {
2
mode: 'checkbox',
3
clickToSelect: true,
4
classes: 'selection-row',
5
};
6
Table rendering
JavaScript
1
7
1
<BootstrapTable
2
keyField="id"
3
data={tableData[0].rowsData}
4
columns={tableData[0].columnsData}
5
selectRow={selectRow}
6
/>
7
I Think issue is coming because of my data, as it is nested one And I am rendering it, but I am not able to resolve it.
My data
JavaScript
1
30
30
1
let tableData = [
2
{
3
rowsData: [
4
{
5
fname: "john",
6
lname: "smith"
7
},
8
{
9
fname: "steve",
10
lname: "warn"
11
},
12
{
13
fname: "michel",
14
lname: "clark"
15
}
16
],
17
columnsData: [
18
{
19
dataField: "fname",
20
text: "First name",
21
sort: true
22
},
23
{
24
dataField: "lname",
25
text: "last Name",
26
sort: true
27
}
28
]
29
}
30
];
Here is my code sandbox link This
Advertisement
Answer
You’re telling keyField="id"
yet each of your rowsData
has no id
. Give each of them an id
and it should work.