简体   繁体   English

如何覆盖反应材料表的操作按钮

[英]How can I override the Actions buttons of Material-Table of react

I'm using material-table in the project we are working on.我在我们正在进行的项目中使用材料表 I need to override the Add button (+ button) and edit button of material-table (marked in the sample image attached), instead of inline adding/editing feature of material-table I want to have a Dialog box (my customized component) should popup in which users will enter their data, then on clicking save button an API call will be performed.我需要覆盖材料表的添加按钮(+ 按钮)和编辑按钮(在附加的示例图像中标记),而不是材料表的内联添加/编辑功能我想要一个对话框(我的自定义组件)应该弹出用户将在其中输入他们的数据,然后单击保存按钮,将执行 API 调用。

Is there a way to do it?有没有办法做到这一点? Can I use EditRow props of Materialtable?我可以使用 Materialtable 的 EditRow 道具吗? If yes can someone give a small example of it on how to use EditRow?如果是的话,有人可以举一个关于如何使用 EditRow 的小例子吗? 在此处输入图像描述

I solved this with the following solution given by a Material-Table contributor Matt Oestreich.我使用 Material-Table 贡献者 Matt Oestreich 提供的以下解决方案解决了这个问题。 I had to use Actions property with my custom onClick handler for custom edit and similarly for Adding set isFreeAction to true in actions prop.我必须将 Actions 属性与我的自定义 onClick 处理程序一起使用以进行自定义编辑,并且类似地在 actions 道具中将 set isFreeAction 添加为 true。

sample code box demo For custom edit operation pass the actions properties like below: 示例代码框演示对于自定义编辑操作,请传递如下操作属性:

<MaterialTable
  // other props
  actions={[
    {
      icon: 'edit',
      tooltip: 'Edit Row',
      onClick: (event, rowData) => {
        // Code to display custom Dialog here
      }
    }
  ]}
/>

For custom add operation pass the actions properties along with isFreeAction prop:对于自定义添加操作,将操作属性与 isFreeAction 属性一起传递:

<MaterialTable
  // other props
  actions={[
    {
      icon: 'add',
      tooltip: 'Add Row',
      // This makes add button to appear in table toolbar instead for each row
      isFreeAction: true 
      onClick: (event, rowData) => {
        // Code to display custom Dialog here
      }
    }
  ]}
/>

my final code would look something like this:我的最终代码看起来像这样:

<MaterialTable
  // other props
  actions={[
    {
      icon: 'edit',
      tooltip: 'Edit Row',
      onClick: (event, rowData) => {
        // Code to display custom Dialog here
      }
    },
    {
      icon: 'add',
      tooltip: 'Add Row',
      // This makes add button to appear in table toolbar instead for each row
      isFreeAction: true 
      onClick: (event, rowData) => {
        // Code to display custom Dialog here
      }
    },
  ]}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM