diff --git a/packages/datalib/src/TableGridDisplay.ts b/packages/datalib/src/TableGridDisplay.ts index a6f6a653c..dba873838 100644 --- a/packages/datalib/src/TableGridDisplay.ts +++ b/packages/datalib/src/TableGridDisplay.ts @@ -69,14 +69,16 @@ export class TableGridDisplay extends GridDisplay { const childAlias = `${column.uniqueName}_ref`; const subcolumns = this.getDisplayColumns(table, column.uniquePath); + this.addReferenceToSelect(select, parentAlias, column); + let added = false; if (this.addJoinsFromExpandedColumns(select, subcolumns, childAlias, columnSources)) added = true; if (this.addAddedColumnsToSelect(select, subcolumns, childAlias, columnSources)) added = true; - if (added) { - this.addReferenceToSelect(select, parentAlias, column); - res = true; - } + // if (added) { + // this.addReferenceToSelect(select, parentAlias, column); + // res = true; + // } } } } @@ -169,7 +171,7 @@ export class TableGridDisplay extends GridDisplay { let res = false; if (this.addJoinsFromExpandedColumns(select, this.columns, 'basetbl', displayedColumnInfo)) res = true; if (this.addHintsToSelect(select)) res = true; - if (select.from.relations) select.from.relations.reverse(); + // if (select.from.relations) select.from.relations.reverse(); return res; } diff --git a/packages/web/src/datagrid/DataGridCore.js b/packages/web/src/datagrid/DataGridCore.js index a4acaed74..a555dffba 100644 --- a/packages/web/src/datagrid/DataGridCore.js +++ b/packages/web/src/datagrid/DataGridCore.js @@ -471,6 +471,33 @@ export default function DataGridCore(props) { } }, [display && display.focusedColumn]); + const rowCountInfo = React.useMemo(() => { + if (selectedCells.length > 1 && selectedCells.every((x) => _.isNumber(x[0]) && _.isNumber(x[1]))) { + let sum = _.sumBy(selectedCells, (cell) => { + const row = loadedRows[cell[0]]; + if (row) { + const colName = realColumnUniqueNames[cell[1]]; + if (colName) { + const data = row[colName]; + if (!data) return 0; + let num = +data; + if (_.isNaN(num)) return 0; + return num; + } + } + return 0; + }); + let count = selectedCells.length; + let rowCount = getSelectedRowData().length; + return `Rows: ${rowCount.toLocaleString()}, Count: ${count.toLocaleString()}, Sum:${sum.toLocaleString()}`; + } + if (allRowCount == null) return 'Loading row count...'; + return `Rows: ${allRowCount.toLocaleString()}`; + // if (this.isLoadingFirstPage) return "Loading first page..."; + // if (this.isFirstPageError) return "Error loading first page"; + // return `Rows: ${this.rowCount.toLocaleString()}`; + }, [selectedCells, allRowCount, loadedRows, visibleRealColumns]); + if (!loadedRows || !columns || columns.length == 0) return ( @@ -525,15 +552,26 @@ export default function DataGridCore(props) { setAutofillDragStartCell(cell); } else { setCurrentCell(cell); - setSelectedCells(getCellRange(cell, cell)); - setDragStartCell(cell); - if (isRegularCell(cell) && !_.isEqual(cell, inplaceEditorState.cell) && _.isEqual(cell, currentCell)) { - // @ts-ignore - dispatchInsplaceEditor({ type: 'show', cell, selectAll: true }); - } else if (!_.isEqual(cell, inplaceEditorState.cell)) { - // @ts-ignore - dispatchInsplaceEditor({ type: 'close' }); + if (event.ctrlKey) { + if (isRegularCell(cell)) { + if (selectedCells.find((x) => x[0] == cell[0] && x[1] == cell[1])) { + setSelectedCells(selectedCells.filter((x) => x[0] != cell[0] || x[1] != cell[1])); + } else { + setSelectedCells([...selectedCells, cell]); + } + } + } else { + setSelectedCells(getCellRange(cell, cell)); + setDragStartCell(cell); + + if (isRegularCell(cell) && !_.isEqual(cell, inplaceEditorState.cell) && _.isEqual(cell, currentCell)) { + // @ts-ignore + dispatchInsplaceEditor({ type: 'show', cell, selectAll: true }); + } else if (!_.isEqual(cell, inplaceEditorState.cell)) { + // @ts-ignore + dispatchInsplaceEditor({ type: 'close' }); + } } } @@ -1131,7 +1169,7 @@ export default function DataGridCore(props) { engine={display.engine} onConfirm={handleConfirmSql} /> - {allRowCount && Rows: {allRowCount.toLocaleString()}} + {allRowCount && {rowCountInfo}} {props.toolbarPortalRef && tabVisible && ReactDOM.createPortal( diff --git a/packages/web/src/utility/metadataLoaders.js b/packages/web/src/utility/metadataLoaders.js index 258111384..ad8518320 100644 --- a/packages/web/src/utility/metadataLoaders.js +++ b/packages/web/src/utility/metadataLoaders.js @@ -118,6 +118,7 @@ export function useDatabaseInfo(args) { async function getDbCore(args, objectTypeField = undefined) { const db = await getDatabaseInfo(args); + if (!db) return null; return db[objectTypeField || args.objectTypeField].find( (x) => x.pureName == args.pureName && x.schemaName == args.schemaName ); @@ -125,6 +126,7 @@ async function getDbCore(args, objectTypeField = undefined) { export function useDbCore(args, objectTypeField = undefined) { const db = useDatabaseInfo(args); + if (!db) return null; return db[objectTypeField || args.objectTypeField].find( (x) => x.pureName == args.pureName && x.schemaName == args.schemaName );