【问题标题】:render a switch button on in material table when i am editing编辑时在材质表中渲染一个开关按钮
【发布时间】:2020-03-29 13:08:54
【问题描述】:

大家好,我正在使用材料表:(开关来自 material-ui,一个简单的切换按钮)

columns: {[{ title: 'Name', field: 'name' },
          { title: 'Status', field: 'status', type: 'boolean', render: rowData => <Switch checked=  {rowData.active}/>*/}
        ]}
        data: {[
            { name: 'Mickey', status: false },
            { name: 'Pippo', status: true}]}

当我点击编辑按钮而不是开关组件时出现一个复选框组件(我认为它是材料表中布尔类型列的默认值),是否可以更改它?

【问题讨论】:

  • 你的代码失败了,请先修复它。

标签: javascript reactjs switch-statement components material-table


【解决方案1】:

在这里使用editComponentrender 应该可以满足您的要求。

{
  title: "Status",
  field: "status",
  editComponent: (rowData) => {
    return <Switch checked={false} inputProps={{ "aria-label": "controlled" }} color="primary" />;
  },
  render: (rowData) => {
    return (
      <Switch
        checked={rowData.status}
        onChange={handleChange}
        inputProps={{ "aria-label": "controlled" }}
        color="primary"
      />
    );
  }
}

【讨论】:

    猜你喜欢
    • 2019-11-02
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 2021-10-09
    • 1970-01-01
    相关资源
    最近更新 更多