[英]How to pass the content of your columns to a dummyField in react-bootstrap-table2
我正在嘗試將列數據字段的值傳遞給 react-bootstrap-table2 dummyField 中的按鈕。 而且我完全不知道該怎么做。 這是我的列數據字段。
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
},
];
我這樣做是因為模態。 我是 React.js 的初學者,特別是 react-bootstrap-table2。
第一種方法:使用狀態將其傳遞給您的組件
export default class yourClassName extends Component{
constructor(props){
super(props);
this.state = {
columns: [ your array data here ]
}
render(){
<yourTable/>
}
}
第二種方法:您可以使用 State Hook https://reactjs.org/docs/hooks-state.html
兩種方法都會產生相同的結果,您可以選擇適合您的編碼風格的一種。
所以它通過這樣做來工作
{
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
},
感謝那些試圖幫助我的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.