ElemeFE / element-react

Element UI
https://elemefe.github.io/element-react/index
MIT License
2.83k stars 443 forks source link

"defaultExpandAll" of table don't take effect when the data is empty initially #1022

Open zhengyhn opened 4 years ago

zhengyhn commented 4 years ago

Description

The Table property "defaultExpandAll" will expand all columns whose type is "type". However, when the table data is empty initially, this function don't take effect.

I found that, every time you rerender the Table, this "expand all" function don't take effect.

Reproduce Steps

const columns = [
    {
      type: 'expand',
      expandPannel: function(data: any){
        return (
          <div>aaa</div>
        )
      }
    }
const data = []
return (<Table
    style={{width: '100%'}}
    columns={columns}
    data={data}
    border={false}
    defaultExpandAll={true}
    />
 )

Now data is an empty array. If we fetch data from backend system and fill data array, then rerender the component, the "expand all" function won't take effect.

Solution

Currently, I use this code to fix this problem.


return ({data.length > 0 && <Table
    style={{width: '100%'}}
    columns={columns}
    data={data}
    border={false}
    defaultExpandAll={true}
    />}
 )