將加號放在指定列
<Table dataSource={dataSource} columns={ahStockColumn} bordered size="small" pagination={false} expandIconAsCell={false} // 將樹形展開 icon 與第一列數據合並 expandedRowRender={this.expandedRowRender} expandIconColumnIndex={1} />
隱藏加號並且點擊指定列數據展開子表格
renderTable = (data) => { const { queryIssuer,dataSource } = this.store;
const ahStockColumn = [ { title: '報告類型', dataIndex: 'companyName', key: 'companyName', align: 'center', width: '50%' }, { title: '報告數', dataIndex: 'data', key: 'data', align: 'center', width: '50%', render: (value, record, index) => { return ( <span onClick={(e) => { this.isExpanded(index); }} > {value} </span> ); } } ]; return ( <Table dataSource={dataSource} columns={ahStockColumn} bordered size="small" pagination={false} expandIconAsCell={false} // 將樹形展開icon 與第一列數據合並 expandedRowRender={this.expandedRowRender} expandedRowKeys={this.state.expandedKey} //展開行的key值(每行必須有key值才能展開) expandIconColumnIndex={-1}/> ); }; isExpanded = (index) => { const expandedKey = this.state.expandedKey; if (expandedKey.indexOf(index) == -1) { expandedKey.push(index); } else { for (let i = 0; i < expandedKey.length; i++) { if (expandedKey[i] === index) { expandedKey.splice(i, 1); } } } this.setState({ expandedKey //設置展開行的key值 }); };