From e6cba97b45c38de38308fc5ca215c55036b232eb Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 15 Mar 2019 13:31:40 -0700 Subject: [PATCH 1/2] disable react table cell measure --- packages/grafana-ui/src/components/Table/Table.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/grafana-ui/src/components/Table/Table.tsx b/packages/grafana-ui/src/components/Table/Table.tsx index a551d6d221d..80f833520e0 100644 --- a/packages/grafana-ui/src/components/Table/Table.tsx +++ b/packages/grafana-ui/src/components/Table/Table.tsx @@ -77,6 +77,8 @@ export class Table extends Component { this.measurer = new CellMeasurerCache({ defaultHeight: 30, defaultWidth: 150, + fixedWidth: true, + fixedHeight: true, }); } From 9bcc9b062c62b5c6375507943b12beb8b58ffd4d Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 15 Mar 2019 13:52:32 -0700 Subject: [PATCH 2/2] calculate the column width --- .../grafana-ui/src/components/Table/Table.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/grafana-ui/src/components/Table/Table.tsx b/packages/grafana-ui/src/components/Table/Table.tsx index 80f833520e0..c32c46f8b88 100644 --- a/packages/grafana-ui/src/components/Table/Table.tsx +++ b/packages/grafana-ui/src/components/Table/Table.tsx @@ -8,6 +8,7 @@ import { CellMeasurerCache, CellMeasurer, GridCellProps, + Index, } from 'react-virtualized'; import { Themeable } from '../../types/theme'; @@ -26,6 +27,7 @@ import { stringToJsRegex } from '../../utils/index'; export interface Props extends Themeable { data: TableData; + minColumnWidth: number; showHeader: boolean; fixedHeader: boolean; fixedColumns: number; @@ -46,6 +48,7 @@ interface State { interface ColumnRenderInfo { header: string; + width: number; builder: TableCellBuilder; } @@ -64,6 +67,7 @@ export class Table extends Component { fixedHeader: true, fixedColumns: 0, rotate: false, + minColumnWidth: 150, }; constructor(props: Props) { @@ -76,9 +80,7 @@ export class Table extends Component { this.renderer = this.initColumns(props); this.measurer = new CellMeasurerCache({ defaultHeight: 30, - defaultWidth: 150, fixedWidth: true, - fixedHeight: true, }); } @@ -112,7 +114,8 @@ export class Table extends Component { /** Given the configuration, setup how each column gets rendered */ initColumns(props: Props): ColumnRenderInfo[] { - const { styles, data } = props; + const { styles, data, width, minColumnWidth } = props; + const columnWidth = Math.max(width / data.columns.length, minColumnWidth); return data.columns.map((col, index) => { let title = col.text; @@ -133,6 +136,7 @@ export class Table extends Component { return { header: title, + width: columnWidth, builder: getCellBuilder(col, style, this.props), }; }); @@ -230,6 +234,10 @@ export class Table extends Component { ); }; + getColumnWidth = (col: Index): number => { + return this.renderer[col.index].width; + }; + render() { const { showHeader, fixedHeader, fixedColumns, rotate, width, height } = this.props; const { data } = this.state; @@ -271,7 +279,7 @@ export class Table extends Component { rowCount={rowCount} overscanColumnCount={8} overscanRowCount={8} - columnWidth={this.measurer.columnWidth} + columnWidth={this.getColumnWidth} deferredMeasurementCache={this.measurer} cellRenderer={this.cellRenderer} rowHeight={this.measurer.rowHeight}