I would like to add a button to each row of react-bootstrap-table 2 and want to bind button click also. But now it does not work.
Here is my code,
InOutHeader() {
return (
<Table className="border-0 m-0 p-0">
<colgroup>
<col width="50" />
<col />
</colgroup>
<thead>
<tr>
<th className="border-0 border-left p-1 text-center" colSpan="2">
In
</th>
</tr>
<tr>
<th className="border-bottom-0 border-left-0 p-1">Time</th>
<th className="border-bottom-0 p-1">Date</th>
</tr>
</thead>
</Table>
);
}
InOutDate(cell, row) {
return (
<Table className="border-0 m-0 p-0">
<thead>
<tr>
<td width="50" className="border-bottom-0 border-left-0 border-top-0 p-1">
{moment(row.ct1).format("hh:mm")}
</td>
<td className="border-bottom-0 border-right-0 border-top-0 p-1">{moment(row.ct1_dd).format("DD-MM-YYYY")}</td>
</tr>
</thead>
</Table>
);
}
GetDateFormat(cell, row) {
return (
moment(row.tdate).format("DD-MM-YYYY ") +
moment(row.tdate)
.format("dddd")
.substring(0, 3)
);
}
GetBooleanFormat(cell, row) {
return row.isapproved ? "True" : "False";
}
GetActionFormat(cell, row) {
return (
<div>
<button type="button" className="btn btn-outline-primary btn-sm ts-buttom" size="sm" onClick={this.handleModelEdit}>
Edit
</button>
<button type="button" className="btn btn-outline-danger btn-sm ml-2 ts-buttom" size="sm">
Delete
</button>
</div>
);
}
getcolumnlist() {
const columns = [
{
dataField: "tdate",
text: "Date",
classes: "p-1",
formatter: this.GetDateFormat,
headerStyle: {
width: "120px"
},
sort: true
},
{
dataField: "empid",
text: "Employee ID",
classes: "p-1",
sort: true
},
{
dataField: "cscid",
text: "Cost Center",
classes: "p-1",
sort: true
},
{
dataField: "shiftid",
text: "Shift ID",
classes: "p-1",
sort: true
},
{
text: "In",
dataField: "ct1",
headerFormatter: this.InOutHeader,
headerStyle: {
padding: "0px",
width: "140px"
},
formatter: this.InOutDate,
classes: "p-0"
},
{
dataField: "isapproved",
text: "Approve",
formatter: this.GetBooleanFormat,
classes: "p-1",
sort: true
},
{
text: "Action",
dataField: "",
formatter: this.GetActionFormat,
classes: "p-1"
}
];
return columns;
}
handleModelEdit() {
console.log("hello");
}
<BootstrapTable keyField={"id"}
data={this.state.timesheetstemp}
columns={this.getcolumnlist()}
>
</BootstrapTable>
When I click the button, it's not going to handlemodeledit function.
Each row shows the button but when there is no onclick function on button and click is not working.
Please let me know how to achieve this issue?
loopto insert the button ineach row.