反应材料表操作按钮标记覆盖多个操作 [英] React Material Table action button markup overriding for multiple actions

查看:49
本文介绍了反应材料表操作按钮标记覆盖多个操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动作覆盖功能允许我覆盖按钮,但它覆盖所有动作按钮.例如,如果我有两个用于编辑和删除的操作按钮,并且我使用了操作覆盖,那么我的两个按钮都会被相同的自定义代码覆盖.如何为不同的按钮指定不同的代码?

Action overriding feature allows me to override button but it overrides all the action buttons. For example, if I have two action buttons for edit and delete and I use the Action overriding, both of my buttons get overridden with that same custom code. How can I specify different codes for different buttons?

我的最终目标是根据 rowData 有条件地禁用编辑和删除按钮.我尝试使用 isEditable 功能,如下面的代码所示,但它也不起作用.

My final goal is to conditionally disable edit and delete buttons based on the rowData. I have tried with isEditable feature as shown in the code below but it doesn't work either.

  ...
  ....
  const components = {
       Action: props => (
           <IconButton aria-label="delete" size="small"
               disabled={props.data.email === 'admin@pipilika.com'}
               onClick={(event) => props.action.onClick(event, props.data)}
               >
               <Icon>delete</Icon>
           </IconButton>
       )

   };

   const actions = [
       {
           icon: 'edit',
           tooltip: 'Edit Index',
           onClick: (event, rowData) => {
               this.onEditClick(null, rowData._id);
           }
       },
       {
           icon: 'delete',
           tooltip: 'Delete Index',
           onClick: (event, rowData) => {
               this.onDeleteClick(null, rowData._id);
           }
       },
   ];


    const options= {
        showTitle: false,
        actionsColumnIndex: -1,
        searchFieldStyle: {
            color: "#fff"
        }
    };

    const editable= {
        isEditable: rowData => rowData.dataType === "html", 
        isDeletable: rowData => rowData.dataType === "html", 
    };

    return(
        <MaterialTable
            editable={editable}
            title="Created Index List"
            columns={columns}
            data={dataTypes}
            actions={actions}
            options={options}
            components={components}
            style={{overflow: 'hidden'}}
        />
    );

推荐答案

对于这个特定的用例,您可以根据这样检查正确的图标名称来选择要呈现的 Button.

for this specific use case, you can choose which Button to render based on checking the right icon name like this.

      components={{
        Action: 
            props => {
                    if(props.action.icon === 'edit'){
                        return(
                        <Button
                        onClick={(event) => props.action.onClick(event, props.data)}
                        color="primary"
                        variant="contained"
                        style={{textTransform: 'none'}}
                        size="small"
                        disabled
                        >
                        My Button 
                        </Button>
                        )
                    }
                    if(props.action.icon === 'save'){
                        return(
                            <Button
                            onClick={(event) => props.action.onClick(event, props.data)}
                            color="primary"
                            variant="contained"
                            style={{textTransform: 'none'}}
                            size="small"
                            >
                            My Button 
                            </Button>
                        )
                    }
                }

      }}

这篇关于反应材料表操作按钮标记覆盖多个操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆