diff --git a/packages/datalib/src/CustomGridDisplay.ts b/packages/datalib/src/CustomGridDisplay.ts index 8af718c8..ef5e96d7 100644 --- a/packages/datalib/src/CustomGridDisplay.ts +++ b/packages/datalib/src/CustomGridDisplay.ts @@ -20,6 +20,8 @@ export interface CustomGridColumn { } export class CustomGridDisplay extends GridDisplay { + customColumns: CustomGridColumn[]; + constructor( public tableName: NamedObjectInfo, columns: CustomGridColumn[], @@ -35,6 +37,8 @@ export class CustomGridDisplay extends GridDisplay { ) { super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion); + this.customColumns = columns; + this.columns = columns.map(col => ({ columnName: col.columnName, headerText: col.columnLabel, @@ -63,12 +67,15 @@ export class CustomGridDisplay extends GridDisplay { createSelect(options = {}) { const select = this.createSelectBase( this.tableName, + [], // @ts-ignore - this.columns.map(col => ({ - columnName: col.columnName, - })), - options + // this.columns.map(col => ({ + // columnName: col.columnName, + // })), + options, + this.customColumns.find(x => x.isPrimaryKey)?.columnName ); + select.selectAll = true; if (this.additionalcondition) { if (select.where) { select.where = { diff --git a/packages/datalib/src/GridDisplay.ts b/packages/datalib/src/GridDisplay.ts index 70656e76..d27c6725 100644 --- a/packages/datalib/src/GridDisplay.ts +++ b/packages/datalib/src/GridDisplay.ts @@ -554,9 +554,9 @@ export abstract class GridDisplay { }; } - createSelectBase(name: NamedObjectInfo, columns: ColumnInfo[], options) { + createSelectBase(name: NamedObjectInfo, columns: ColumnInfo[], options, defaultOrderColumnName?: string) { if (!columns) return null; - const orderColumnName = columns[0].columnName; + const orderColumnName = defaultOrderColumnName ?? columns[0]?.columnName; const select: Select = { commandType: 'select', from: { @@ -732,6 +732,7 @@ export abstract class GridDisplay { alias: 'count', }, ]; + select.selectAll = false; } return select; // const sql = treeToSql(this.driver, select, dumpSqlSelect); diff --git a/packages/sqltree/src/dumpSqlCommand.ts b/packages/sqltree/src/dumpSqlCommand.ts index 0a1bda7a..b16f3c34 100644 --- a/packages/sqltree/src/dumpSqlCommand.ts +++ b/packages/sqltree/src/dumpSqlCommand.ts @@ -15,7 +15,7 @@ export function dumpSqlSelect(dmp: SqlDumper, cmd: Select) { if (cmd.selectAll) { dmp.put('* '); } - if (cmd.columns) { + if (cmd.columns && cmd.columns.length > 0) { if (cmd.selectAll) dmp.put('&n,'); dmp.put('&>&n'); dmp.putCollection(',&n', cmd.columns, fld => {