From 9c33f83ae9358da689333320a2141e7d90ed4a60 Mon Sep 17 00:00:00 2001 From: "vicky_primathon.in" Date: Thu, 25 Jun 2020 12:48:51 +0530 Subject: [PATCH] Taking keys from all data points of table to generate columns intead of just first data point of table data --- .../appsmith/ReactTableComponent.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/client/src/components/designSystems/appsmith/ReactTableComponent.tsx b/app/client/src/components/designSystems/appsmith/ReactTableComponent.tsx index 49bc5a228b..4a05745a58 100644 --- a/app/client/src/components/designSystems/appsmith/ReactTableComponent.tsx +++ b/app/client/src/components/designSystems/appsmith/ReactTableComponent.tsx @@ -185,13 +185,28 @@ export class ReactTableComponent extends React.Component< }); } + getAllTableColumnKeys = () => { + const tableData: object[] = this.props.tableData; + const columnKeys: string[] = []; + for (let i = 0, tableRowCount = tableData.length; i < tableRowCount; i++) { + const row = tableData[i]; + for (const key in row) { + if (!columnKeys.includes(key)) { + columnKeys.push(key); + } + } + } + return columnKeys; + }; + getTableColumns = () => { const tableData: object[] = this.props.tableData; let columns: ReactTableColumnProps[] = []; const hiddenColumns: ReactTableColumnProps[] = []; if (tableData.length) { - const row = tableData[0]; - for (const i in row) { + const columnKeys: string[] = this.getAllTableColumnKeys(); + for (let index = 0, length = columnKeys.length; index < length; index++) { + const i = columnKeys[index]; const columnName: string = this.props.columnNameMap && this.props.columnNameMap[i] ? this.props.columnNameMap[i]