javascript - 如何在按钮的onclick事件上以编程方式选择材料表的行-React js
问题描述
我正在使用 Material-Table 。我需要根据某些条件在单击按钮时选择多行。条件写在下面的代码中。谁能指导我如何根据某些条件选择多行?
<MaterialTable
icons={tableIcons}title=""
columns={[
{ title: 'Project Name', field: 'Project_Name', render: rowData => <Link to='/projectdetails'>{rowData.Project_Name}</Link> },
{ title: 'Methods Covered', field: 'Methods_Covered', type: 'numeric' },
{ title: 'Methods not Covered', field: 'Methods_not_Covered', type: 'numeric' },
{ title: 'Total Methods', field: 'Total_Methods', type: 'numeric' },
]}
data={this.state.results}
components={{
Toolbar: props => (
<div>
<MTableToolbar {...props} />
<div className="Mtable">
<div>
<Button color="primary" onClick={rowData =>
(rowData.Methods_Covered ?
rowData.tableData.checked = true :
rowData.tableData.checked = false)}>
select Highlighted</Button>
</div>
</div>
</div>
),
}}
onSelectionChange={this.handleSelect}
onRowClick={this.handleRowClick}
options={{
sorting: true,
selection: true,
search: true,
searchAutoFocus: true,
searchFieldAlignment: 'right',
searchFieldStyle: {
border: 'solid black 2px',
},
}}
/>
解决方案
我没有尝试过OP的代码,但是有这个问题的人可以检查MaterialTable的props的selectionProps
属性:options
options={{
sorting: true,
selection: true,
search: true,
searchAutoFocus: true,
searchFieldAlignment: 'right',
searchFieldStyle: {
border: 'solid black 2px',
},
selectionProps: ({ tableData: { checked } }) => ({
checked
}),
}}
请在此处查看最后一个示例:https ://material-table.com/#/docs/features/selection
推荐阅读
- salesforce - Salesforce 工作流规则在沙盒上运行良好,但在生产上却不行
- javascript - NodeJS:Promise 被拒绝后运行 WriteStream 关闭事件
- python - 如何将输出更改为文本文件?
- javascript - 如何在js中设置密码和关键事件条件?
- database - 将 Oracle 12c 升级到 18c 时对象无效
- wordpress - 停止 WooCommerce 以减少废弃管理员新订单的库存
- javascript - 如何增加 Vue 应用程序的 max-http-header-size
- javascript - Laravel 中的 VueJS 组件实现中的鼠标悬停
- spring-boot - 如何在执行期间更改 Spring Batch 中的 JobParameters?
- jquery - bootbox 确认弹出框没有出现并且页面冻结