oHo*_*hov 6 reactjs material-ui material-table
我想做这个(选定的一些动作和每一行的一些动作)。请帮忙,谢谢!
我用material-table用ReactJS。现在我对每一行都有没有选择的动作,如果添加选择道具,这些动作就会消失。我不知道如何将每一行动作与多个动作结合起来。
您可以将position: 'row'道具添加到动作中。道具有 4 个可用选项position:auto', toolbar, toolbarOnSelect,row
这个最小的代码片段应该可以工作
<MaterialTable
actions={[
{
icon: 'save',
tooltip: 'Save User',
position: 'row',
onClick: (event, rowData) => alert('You saved ' + rowData.name)
},
{
icon: 'delete',
tooltip: 'Delete User',
position: 'row',
onClick: (event, rowData) =>
alert('You want to delete ' + rowData.name)
}
]}
columns={[
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: '?stanbul', 63: '?anl?urfa' }
}
]}
data={[
{
name: 'Mehmet',
surname: 'Baran',
birthYear: 1987,
birthCity: 63
},
{
name: 'Zerya Betül',
surname: 'Baran',
birthYear: 2017,
birthCity: 34
}
]}
options={{
selection: true,
actionsColumnIndex: -1
}}
title="Positioning Actions Column Preview"
/>
Run Code Online (Sandbox Code Playgroud)
这是源代码中决定当属性设置为true时是否显示操作列的确切位置:selection
if (this.props.actions && this.props.actions.filter(a => !a.isFreeAction && !this.props.options.selection).length > 0) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
另一个这样的地方是在renderActions 方法中:
const actions = this.props.actions.filter(a => !a.isFreeAction && !this.props.options.selection);
Run Code Online (Sandbox Code Playgroud)
所以它要么必须是 aisFreeAction要么selection应该设置为false。目前可以自定义此组件的唯一方法是覆盖Row组件 - 基本上是复制/粘贴它,修改这些条件,将结果导入为新组件并将其提供在配置components的属性中作为.material-tableRow
CodeSandbox:https://codesandbox.io/s/jovial-architecture-ggnrl
| 归档时间: |
|
| 查看次数: |
8067 次 |
| 最近记录: |