Antd Design【Table】- 在加载表格数据时如何展开特定行

huangapple go评论70阅读模式
英文:

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 : &quot;A&quot;
},
{
   key : 2,
   name : &quot;B&quot;
}]

Sample Code:

&lt;Table
   dataSource={data}
   expandable={{
      expandIcon: () =&gt; &lt;div /&gt;
    }}
 /&gt;

答案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? &lt;Table
            dataSource={data},
            defaultExpandedRowKeys = {[2]}
            expandable={{
                expandIcon: () =&gt; &lt;div /&gt;
            }}
         /&gt; : &#39;Loading...&#39; }

huangapple
  • 本文由 发表于 2023年5月22日 15:00:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303688.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定