From 666526389a8eda1aac09d1b9ef0afd86605230ae Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Mon, 27 May 2019 19:29:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20table=20=E8=A1=A8=E5=A4=B4?= =?UTF-8?q?=E5=88=86=E7=BB=84=E5=90=8E,=20=E5=9B=BA=E5=AE=9A=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=AE=BD=E5=BA=A6=E5=A6=82=E5=86=85=E5=AE=B9=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=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 | 20 ++++++++++---------- src/store/table.ts | 8 ++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/renderers/Table.tsx b/src/renderers/Table.tsx index 0f9a83a2f..734f67d45 100644 --- a/src/renderers/Table.tsx +++ b/src/renderers/Table.tsx @@ -461,9 +461,9 @@ export default class Table extends React.Component { let heights: { [propName: string]: number; } = (this.heights = {}); - forEach(table.querySelectorAll('thead>tr:first-child>th'), (item: HTMLElement) => { + forEach(table.querySelectorAll('thead>tr:last-child>th'), (item: HTMLElement) => { heights.header || (heights.header = item.offsetHeight); - widths[item.getAttribute('index') as string] = item.offsetWidth; + widths[item.getAttribute('data-index') as string] = item.offsetWidth; }); forEach( table.querySelectorAll('tbody>tr>*:first-child'), @@ -491,8 +491,8 @@ export default class Table extends React.Component { `.${ns}Table-fixedTop table, .${ns}Table-fixedLeft table, .${ns}Table-fixedRight table` ), table => { - forEach(table.querySelectorAll('thead>tr>th'), (item: HTMLElement) => { - item.style.cssText = `width: ${this.widths[parseInt(item.getAttribute('index') as string, 10)]}px`; + forEach(table.querySelectorAll('thead>tr:last-child>th'), (item: HTMLElement) => { + item.style.cssText = `width: ${this.widths[parseInt(item.getAttribute('data-index') as string, 10)]}px`; }); forEach(table.querySelectorAll('tbody>tr'), (item: HTMLElement, index) => { @@ -899,7 +899,7 @@ export default class Table extends React.Component { {store.columnGroup.length ? ( {store.columnGroup.map((item, index) => ( - {item.label} + {item.label} ))} ) : null} @@ -907,7 +907,7 @@ export default class Table extends React.Component { {store.filteredColumns.map(column => this.renderHeadCell(column, { key: column.index, - index: column.index, + 'data-index': column.index, }) )} @@ -938,7 +938,7 @@ export default class Table extends React.Component { {store.columnGroup.length ? ( {store.columnGroup.map((item, index) => ( - {item.label} + {item.label} ))} ) : null} @@ -946,7 +946,7 @@ export default class Table extends React.Component { {columns.map(column => this.renderHeadCell(column, { key: column.index, - index: column.index, + 'data-index': column.index, }) )} @@ -1358,14 +1358,14 @@ export default class Table extends React.Component { {store.columnGroup.length ? ( {store.columnGroup.map((item, index) => ( - {item.label} + {item.label} ))} ) : null} {store.filteredColumns.map(column => this.renderHeadCell(column, { - index: column.index, + 'data-index': column.index, key: column.index, }) )} diff --git a/src/store/table.ts b/src/store/table.ts index 0cfdfdbd3..d4a41fad1 100644 --- a/src/store/table.ts +++ b/src/store/table.ts @@ -255,6 +255,7 @@ export const TableStore = iRendererStore function getColumnGroup():Array<{ label: string, + index: number, colSpan: number }> { const columsn = getFilteredColumns(); @@ -266,11 +267,13 @@ export const TableStore = iRendererStore const result:Array<{ label: string, + index: number, colSpan: number }> = [ { label: columsn[0].groupName, - colSpan: 1 + colSpan: 1, + index: columsn[0].index } ]; @@ -288,7 +291,8 @@ export const TableStore = iRendererStore } else { result.push({ label: current.groupName, - colSpan: 1 + colSpan: 1, + index: current.index }); } }