检查是不是选择了 MUIDataTable onRowSelect?
Posted
技术标签:
【中文标题】检查是不是选择了 MUIDataTable onRowSelect?【英文标题】:Check if MUIDataTable onRowSelect is selected?检查是否选择了 MUIDataTable onRowSelect? 【发布时间】:2021-07-10 21:17:31 【问题描述】:如何知道在 onRowSelect 方法中该行是否被选中?
import MUIDataTable from "mui-datatables";
...
const [ total, setTotal ] = useState(0);
...
const handleRowSelect = (curRowSelected) =>
console.log(curRowSelected);
const val = credits[curRowSelected[0].index].amount;
// I want to add a condition: IF selected, I'll add value to my total variable; otherwise, I'll subtract
const options =
filterType: 'dropdown',
pagination: false,
onRowsSelect: handleRowSelect
;
...
<MUIDataTable
title="Payments"
data=credits
columns=columns
options=options
/>
【问题讨论】:
【参考方案1】:您可以在选项中传递isRowSelectable
,这将为您提供所选行的索引。
const columns = [....]
const data = [...]
const options =
...whateverOptionsYouHave,
onRowSelect: (selectedRows) =>
// selectedRows would be an array of objects containing index and dataIndex
/*
selectRows = [
dataIndex: 0, // will be index of selected row
index: 0
]
*/
console.log(selectedRows)
// write code to whatever you want to with selected row
<MUIDataTable options=options columns=columns data=data />
【讨论】:
以上是关于检查是不是选择了 MUIDataTable onRowSelect?的主要内容,如果未能解决你的问题,请参考以下文章
MUIDataTable 我想隐藏复选框,但当我点击行时我也想要行数据