You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 15:39:19