Material-Table 在 React 中。使用状态变量动态设置 table 选项

Material-Table in React. Dynamically setting table options with state variables

我是新手 Material-Table table。我正在尝试根据用户的选择来设置其选项。

例如,我想根据用户是否要过滤来打开 on/off 过滤。

我有一个按钮,它根据选择的时间将状态变量设置为 true 或 false。

    this.state = {
        filterStatus:false,
    }

但是我的选项属性不允许我使用状态变量。

     options={{
           filtering: {this.state.filterStatus}
             }}

有办法吗?

我希望用户能够通过按钮简单地选择关闭过滤。

从这里开始,

enter image description here

至此

enter image description here

您可以在 MaterialTable 中的 options 下使用 filtering,如下所示:

<MaterialTable
            title="Basic Filtering Preview"
            columns={state.columns}
            data={state.data}
            options={{
                filtering: state.filtering
            }}
            icons={tableIcons}
        />

在这个例子中,我使用了 toggle button 来运行 off/on 过滤。

Here is the Code Sandbox