|
@@ -61,6 +61,7 @@ export class Table extends Component<Props, State> {
|
|
|
renderer: ColumnRenderInfo[];
|
|
renderer: ColumnRenderInfo[];
|
|
|
measurer: CellMeasurerCache;
|
|
measurer: CellMeasurerCache;
|
|
|
scrollToTop = false;
|
|
scrollToTop = false;
|
|
|
|
|
+ rotateWidth = 100;
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
static defaultProps = {
|
|
|
showHeader: true,
|
|
showHeader: true,
|
|
@@ -85,7 +86,7 @@ export class Table extends Component<Props, State> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps: Props, prevState: State) {
|
|
componentDidUpdate(prevProps: Props, prevState: State) {
|
|
|
- const { data, styles, showHeader } = this.props;
|
|
|
|
|
|
|
+ const { data, styles, showHeader, rotate } = this.props;
|
|
|
const { sortBy, sortDirection } = this.state;
|
|
const { sortBy, sortDirection } = this.state;
|
|
|
const dataChanged = data !== prevProps.data;
|
|
const dataChanged = data !== prevProps.data;
|
|
|
const configsChanged =
|
|
const configsChanged =
|
|
@@ -105,6 +106,11 @@ export class Table extends Component<Props, State> {
|
|
|
this.renderer = this.initColumns(this.props);
|
|
this.renderer = this.initColumns(this.props);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (dataChanged || rotate !== prevProps.rotate) {
|
|
|
|
|
+ const { width, minColumnWidth } = this.props;
|
|
|
|
|
+ this.rotateWidth = Math.max(width / data.rows.length, minColumnWidth);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Update the data when data or sort changes
|
|
// Update the data when data or sort changes
|
|
|
if (dataChanged || sortBy !== prevState.sortBy || sortDirection !== prevState.sortDirection) {
|
|
if (dataChanged || sortBy !== prevState.sortBy || sortDirection !== prevState.sortDirection) {
|
|
|
this.scrollToTop = true;
|
|
this.scrollToTop = true;
|
|
@@ -115,6 +121,10 @@ export class Table extends Component<Props, State> {
|
|
|
/** Given the configuration, setup how each column gets rendered */
|
|
/** Given the configuration, setup how each column gets rendered */
|
|
|
initColumns(props: Props): ColumnRenderInfo[] {
|
|
initColumns(props: Props): ColumnRenderInfo[] {
|
|
|
const { styles, data, width, minColumnWidth } = props;
|
|
const { styles, data, width, minColumnWidth } = props;
|
|
|
|
|
+ if (!data || !data.fields || !data.fields.length || !styles) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const columnWidth = Math.max(width / data.fields.length, minColumnWidth);
|
|
const columnWidth = Math.max(width / data.fields.length, minColumnWidth);
|
|
|
|
|
|
|
|
return data.fields.map((col, index) => {
|
|
return data.fields.map((col, index) => {
|
|
@@ -235,12 +245,18 @@ export class Table extends Component<Props, State> {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
getColumnWidth = (col: Index): number => {
|
|
getColumnWidth = (col: Index): number => {
|
|
|
|
|
+ if (this.props.rotate) {
|
|
|
|
|
+ return this.rotateWidth; // fixed for now
|
|
|
|
|
+ }
|
|
|
return this.renderer[col.index].width;
|
|
return this.renderer[col.index].width;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
const { showHeader, fixedHeader, fixedColumns, rotate, width, height } = this.props;
|
|
const { showHeader, fixedHeader, fixedColumns, rotate, width, height } = this.props;
|
|
|
const { data } = this.state;
|
|
const { data } = this.state;
|
|
|
|
|
+ if (!data || !data.fields || !data.fields.length) {
|
|
|
|
|
+ return <span>Missing Fields</span>; // nothing
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
let columnCount = data.fields.length;
|
|
let columnCount = data.fields.length;
|
|
|
let rowCount = data.rows.length + (showHeader ? 1 : 0);
|
|
let rowCount = data.rows.length + (showHeader ? 1 : 0);
|