I'm trying to pass the value of my columns datafield to my buttons in react-bootstrap-table2 dummyField. And I don't quite know how to do it. this is my columns datafield.
const columns = [
{
dataField: "firstName",
text: "First Name",
},
{
dataField: "middleName",
text: "Middle Name",
},
{
dataField: "lastName",
text: "Last Name",
},
{
dataField: "sex",
text: "Sex",
sort: true,
},
{
dataField: "rootChapter",
text: "Root Chapter",
},
{
dataField: "municipalCouncil.name",
text: "Council",
sort: true,
},
{
dataField: "batchName",
text: "Batch Name",
sort: true,
},
{
dataField: "alias",
text: "Alias",
},
{
dataField: "actions",
text: "Actions",
isDummyField: true,
formatter: (cell, row) => <MemberButtons member={columns} id={row._id} />, // Overhere is the problem
},
];
I'm doing this because of the modal. I'm a beginner to React.js and specially to react-bootstrap-table2.
1st approach : Use state to pass it to your component
export default class yourClassName extends Component{
constructor(props){
super(props);
this.state = {
columns: [ your array data here ]
}
render(){
<yourTable/>
}
}
2nd approach : you can use State Hook https://reactjs.org/docs/hooks-state.html
Both approaches will yield same results, you can pick the one that suits your coding style.
So it works by doing this
{
dataField: "actions",
text: "Actions",
isDummyField: true,
formatter: (cell, row) => <MemberButtons values={row} id={row._id} />, // By passing row variable to values I got all the contents of my datafields
},
Thank you for those who tried to help me.. If you found a better way to do this please dont hesitate to post it here.. Thanks :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.