From 286f4836fa2826d429280efc0e84b1def59efe92 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Thu, 28 May 2020 12:10:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Nested=20Table=20=E5=88=97?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Table.tsx | 69 ++++++++++++++++++++--------------------- src/store/table.ts | 14 +++++++-- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/renderers/Table.tsx b/src/renderers/Table.tsx index 7723c249..a39d5024 100644 --- a/src/renderers/Table.tsx +++ b/src/renderers/Table.tsx @@ -1189,7 +1189,13 @@ export default class Table extends React.Component { ); } - renderCell(region: string, column: IColumn, item: IRow, props: any) { + renderCell( + region: string, + column: IColumn, + item: IRow, + props: any, + ignoreDrag = false + ) { const { render, store, @@ -1255,6 +1261,7 @@ export default class Table extends React.Component { let prefix: React.ReactNode = null; if ( + !ignoreDrag && column.isPrimary && store.isNested && store.draggable && @@ -1305,6 +1312,7 @@ export default class Table extends React.Component {
{store.leftFixedColumns.length ? this.renderFixedColumns( + store.rows, store.leftFixedColumns, true, tableClassName @@ -1314,6 +1322,7 @@ export default class Table extends React.Component {
{store.rightFixedColumns.length ? this.renderFixedColumns( + store.rows, store.rightFixedColumns, true, tableClassName @@ -1352,6 +1361,7 @@ export default class Table extends React.Component { } renderFixedColumns( + rows: Array, columns: Array, headerOnly: boolean = false, tableClassName: string = '' @@ -1408,36 +1418,15 @@ export default class Table extends React.Component { {headerOnly ? null : ( - {store.rows.length ? ( - store.rows.map((item, rowIndex) => { - const itemProps = buildItemProps - ? buildItemProps(item, rowIndex) - : null; - - return ( - - ); + {rows.length ? ( + this.renderRows(rows, columns, { + regionPrefix: 'fixed/', + renderCell: ( + region: string, + column: IColumn, + item: IRow, + props: any + ) => this.renderCell(region, column, item, props, true) }) ) : ( @@ -1713,7 +1702,11 @@ export default class Table extends React.Component { : footerNode || toolbarNode || null; } - renderRows(rows: Array): any { + renderRows( + rows: Array, + columns = this.props.store.filteredColumns, + rowProps: any = {} + ): any { const { store, rowClassName, @@ -1747,13 +1740,14 @@ export default class Table extends React.Component { 'is-expandable': item.expandable } )} - columns={store.filteredColumns} + columns={columns} renderCell={this.renderCell} render={render} onAction={onAction} onCheck={this.handleCheck} // todo 先注释 quickEditEnabled={item.depth === 1} onQuickChange={store.dragging ? null : this.handleQuickChange} + {...rowProps} /> ]; @@ -1773,7 +1767,7 @@ export default class Table extends React.Component { ? filter(rowClassNameExpr, item.data) : rowClassName )} - columns={store.footableColumns} + columns={columns} renderCell={this.renderCell} render={render} onAction={onAction} @@ -1781,12 +1775,13 @@ export default class Table extends React.Component { footableMode footableColSpan={store.filteredColumns.length} onQuickChange={store.dragging ? null : this.handleQuickChange} + {...rowProps} /> ); } } else if (Array.isArray(item.data.children)) { // 嵌套表格 - doms.push(...this.renderRows(item.children)); + doms.push(...this.renderRows(item.children, columns, rowProps)); } } return doms; @@ -1886,7 +1881,7 @@ export default class Table extends React.Component { {store.rows.length ? ( - this.renderRows(store.rows) + this.renderRows(store.rows, store.filteredColumns) ) : ( @@ -1936,6 +1931,7 @@ export default class Table extends React.Component {
{affixColumns !== false && store.leftFixedColumns.length ? this.renderFixedColumns( + store.rows, store.leftFixedColumns, false, tableClassName @@ -1945,6 +1941,7 @@ export default class Table extends React.Component {
{affixColumns !== false && store.rightFixedColumns.length ? this.renderFixedColumns( + store.rows, store.rightFixedColumns, false, tableClassName diff --git a/src/store/table.ts b/src/store/table.ts index 4bb94077..e7500553 100644 --- a/src/store/table.ts +++ b/src/store/table.ts @@ -245,7 +245,16 @@ export const TableStore = iRendererStore return []; } - return getFilteredColumns().filter(item => item.fixed === 'left'); + let columns = getFilteredColumns().filter(item => item.fixed === 'left'); + + // 有才带过去,没有就不带了 + if (columns.length) { + columns = getFilteredColumns().filter( + item => item.fixed === 'left' || /^__/.test(item.type) + ); + } + + return columns; } function getRightFixedColumns() { @@ -513,14 +522,13 @@ export const TableStore = iRendererStore columns.unshift({ type: '__expandme', toggable: false, - // fixed: 'left', className: 'Table-expandCell' }); columns.unshift({ type: '__checkme', - toggable: false, fixed: 'left', + toggable: false, className: 'Table-checkCell' });