Solution to the failure of defaultExpandAllRows in Ant-Design's Table

Today, when I use Ant-Design to write an expandable list, I want the table to be fully expanded by default. So I found the defaultExpandAllRows attribute in the API, which can achieve the ideal function. Its default value is false, just change it to true.

But when using it, I found that the form did not expand automatically.

Later, I checked the information and learned that defaultExpandAllRows will only be triggered during the first rendering. At that time, the data of the table is often empty. And now, the page doesn't know how many times to render.

Solution: Set a key value. Once the key value changes, it will automatically become a new component, thus solving this problem.

As shown in the code below, the data here is the data rendered in the table, and the key changes when the data changes.

 <Table key={data} defaultExpandAllRows={true} >

Hope to help you

Guess you like

Origin blog.csdn.net/qq_58174484/article/details/125547038