英文:
Antd Design [Table] - How to expand specific row on table data load
问题
I want to expand specific row of table in antd design. Assuming all the other things are working fine. In below code, need to expand row 2 i.e name = 'B' on data load.
Sample Json:
let tableSourceData = [{
key : 1,
name : "A"
},
{
key : 2,
name : "B"
}]
Sample Code:
<Table
dataSource={data}
expandable={{
expandIcon: () => <div />
}}
/>
英文:
I want to expand specific row of table in antd design. Assuming all the other things are working fine. In below code, need to expand row 2 i.e name = 'B' on data load.
Sample Json:
let tableSourceData = [{
key : 1,
name : "A"
},
{
key : 2,
name : "B"
}]
Sample Code:
<Table
dataSource={data}
expandable={{
expandIcon: () => <div />
}}
/>
答案1
得分: 1
我能够使用 prop: defaultExpandedRowKeys
(https://ant.design/components/table#API)。
确保在数据加载后调用它,并且需要提供一个字符串/数字数组的值:
defaultExpandedRowKeys={[2]}
英文:
As I have searched for specific answer, but not able to find it. Now based of trial and error able to make progress.
Answer:
We can use prop: defaultExpandedRowKeys (https://ant.design/components/table#API)
Make sure it should be called after data loading and need to provide value as array of string/number
{ data? <Table
dataSource={data},
defaultExpandedRowKeys = {[2]}
expandable={{
expandIcon: () => <div />
}}
/> : 'Loading...' }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论