如何在Material React Table中禁止特定列的编辑权限?
如何在Material React Table中设置部分字段为只读
在Material React Table中,要将特定字段设为只读,只需在对应列的配置里添加 editable: false 属性即可,以此覆盖默认的可编辑行为。
修改后的代码示例如下:
import MaterialReactTable from 'material-react-table' const columns = [ { headerName: 'ID', accessorKey: 'categoryId', width: 20, editable: false // 标记该字段为只读 }, { headerName: 'Name', accessorKey: 'categoryName', width: 220, editable: true }, { headerName: 'Game System', width: 220, accessorKey: 'gameSystemId', type: 'numeric', editable: true, }, ] <MaterialReactTable columns={columns} loading={loading} data={allCategories} onEditingRowSave={onRowAdd} />
当表格进入编辑状态时,设置了editable: false的列会自动变为不可编辑状态(例如显示为纯文本而非可输入控件),完全满足只读需求。
内容的提问来源于stack exchange,提问作者Jamie Hutber
相关产品推荐
相关产品推荐

