【问题标题】:React antd expandedRowRender - Only open one row at a timeReact antd expandRowRender - 一次只打开一行
【发布时间】:2017-09-15 13:59:15
【问题描述】:

我创建了一个反应表并使用ant design

有没有一种蚂蚁设计的解决方案,允许expandedRowRender 函数一次只用于一行。

如果展开一行,我想隐藏所有其他展开图标。

【问题讨论】:

  • 您的查询有什么解决方案吗??
  • 将rowKey参数传给表格组件

标签: reactjs antd


【解决方案1】:

这很简单。您将需要利用<Table /> 组件的expandedRowKeys 属性。该属性存储当前展开的行键的值。所以,我们要做的就是只设置当前展开的行键并删除其他的。

render()

<Table
    expandedRowKeys={this.state.expandedRowKeys}
    onExpand={this.onTableRowExpand}
/>

onExpand回调

onTableRowExpand(expanded, record){
    var keys = [];
    if(expanded){
        keys.push(record.id); // I have set my record.id as row key. Check the documentation for more details.
    }

    this.setState({expandedRowKeys: keys});
}

更多阅读: &lt;Table /&gt; API Documentation

2021 年更新

如果你使用钩子

// useState()
const [expandedRowKeys, setExpandedRowKeys] = useState([]);

render()

<Table
    expandedRowKeys={expandedRowKeys}
    onExpand={onTableRowExpand}
/>

onExpand回调

const onTableRowExpand = (expanded, record) => {
    const keys = [];
    if(expanded){
        keys.push(record.id); // I have set my record.id as row key. Check the documentation for more details.
    }

    setExpandedRowKeys(keys);
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 2017-11-21
相关资源
最近更新 更多