【问题标题】:Button Not Showing On React Table按钮未显示在反应表上
【发布时间】:2021-11-20 05:14:23
【问题描述】:

我遇到了一些麻烦。我试图在 React Table 上为每一行显示一个按钮,但它没有显示,它只显示一个空白列。 这是我的专栏

columns = [
  
    {
        dataField: "nama_user",
        text: "Nama",
        sort: true,
        style: { overflowWrap: "break-word" }, 
        headerStyle: { backgroundColor: '#2196F3' , color: 'white'}
    },
    {
        dataField: "email",
        text: "Email",
        sort: true,
        headerStyle: { backgroundColor: '#2196F3' , color: 'white'}
    },
    {
        dataField: "",
        text: "Action",
        formatter: this.GetUserAction,
        headerStyle: { backgroundColor: '#2196F3' , color: 'white'},
        classes: "p-1"
    }
];

这是包含按钮的函数

GetUserAction = (cell, row, rowIndex, formatExtraData) => {
        return (
            <div>
                <button className="update" onClick={this.handleClickOpen}>
                    Edit
                </button>
                <button className="update" onClick={this.aktivasiUser(row)}>
                   Aktivasi
                </button>
            </div>
        );
    }

也许我错过了我的代码中的某些内容?感谢您的回答。

【问题讨论】:

    标签: reactjs react-table


    【解决方案1】:

    你的代码对我来说很不清楚,如果我没记错的话,Edit这个词正在存储一些值,这就是你想要显示为函数的内容,对吗? 如果是,则尝试将 Edit 值括在花括号中,因为在 jsx 中,如果要解释某些变量的内容,则必须将其括在花括号 {} 中。

    花括号是一种特殊语法,让 JSX 解析器知道它需要将它们之间的内容解释为 JavaScript 而不是字符串。这个过程一般称为“插值”

    尝试做这样的事情

    让我知道这是否可行,否则请尝试添加更多代码以便我理解

    【讨论】:

    • 啊,不,Edit 根本不存储任何值,它只是按钮的纯文本。
    • @AnandaPramono 好吧,兄弟你的问题不太清楚,你能编辑你的帖子并向我们展示完整的代码吗?这对理解很重要
    【解决方案2】:

    看来我找到了问题所在。需要将columns 放在render() 里面,而不是放在外面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2021-09-29
      • 2021-09-12
      • 1970-01-01
      • 2019-04-23
      相关资源
      最近更新 更多