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 }); } }