Code snippet to add a checkbox in each row of a primereact datatable.
In Column tag we need to add selectionmode attribute to add checkbox in datatable.
import React, { Component } from 'react';
import {DataTable} from 'primereact/datatable';
import {Column} from 'primereact/column';
export class DTColumnCheckBoxDemo extends Component {
constructor() {
super();
this.state = {
}
}
render() {
return (
<DataTable value={this.state.list}}
selection={this.state.listItem} onSelectionChange={(e) => this.setState({listItem: e.data})} >
<Column em="" selectionmode="multiple" />
<Column field="xyz" header="XYZ" />
<Column field="abc" header="ABC" />
</DataTable>
);
}
In Column tag we need to add selectionmode attribute to add checkbox in datatable.