I have a ant design table with a checkbox in the column "attendance" i want to switch the state of that attendance for example i want to change the state from "absent" to "present" or vice versa, depending if the checkbox is checked or not. But i don't have idea how to do that. I will share my code below:
import { Col, Form, Row, Select, Table, Input } from "antd";
const { Option } = Select;
function AsistenciaDia() {
const columns = [
{
title: "NOMBRE",
dataIndex: "name",
align: "center",
},
Table.SELECTION_COLUMN,
{
title: "ASISTENCIA",
dataIndex: "asist",
align: "center",
},
];
const data = [];
for (let i = 0; i < 40; i++) {
data.push({
key: i,
name: `nombre ${i}`,
asist: 'Absent',
});
}
return (
<
<div className="container-asist-dia">
<Table
className="asist-dia"
columns={columns}
rowSelection={{}}
dataSource={data}
pagination={false}
scroll={{ y: 400 }}
/>
</div>
</>
);
}
export default AsistenciaDia;
Use the rowSelection prop of Table.
In this you will get selected row object and just update the true/false flag based on your requirement.
If flag value if true than set present otherwise absent.
Link: https://codesandbox.io/s/w43hup