diff --git a/src/main/ipc-handlers/tables.js b/src/main/ipc-handlers/tables.js index ecb1ba06..c3183471 100644 --- a/src/main/ipc-handlers/tables.js +++ b/src/main/ipc-handlers/tables.js @@ -14,14 +14,18 @@ export default (connections) => { } }); - ipcMain.handle('get-table-data', async (event, { uid, schema, table }) => { + ipcMain.handle('get-table-data', async (event, { uid, schema, table, sortParams }) => { try { - const result = await connections[uid] + const query = connections[uid] .select('*') .schema(schema) .from(table) - .limit(1000) - .run({ details: true }); + .limit(1000); + + if (sortParams && sortParams.field && sortParams.dir) + query.orderBy({ [sortParams.field]: sortParams.dir.toUpperCase() }); + + const result = await query.run({ details: true }); return { status: 'success', response: result }; } diff --git a/src/renderer/components/WorkspaceQueryTab.vue b/src/renderer/components/WorkspaceQueryTab.vue index 2aa53481..0ef68bdf 100644 --- a/src/renderer/components/WorkspaceQueryTab.vue +++ b/src/renderer/components/WorkspaceQueryTab.vue @@ -99,6 +99,7 @@ export default { if (!query || this.isQuering) return; this.isQuering = true; this.clearTabData(); + this.$refs.queryTable.resetSort(); try { // Query Data const params = { diff --git a/src/renderer/components/WorkspaceQueryTable.vue b/src/renderer/components/WorkspaceQueryTable.vue index 94997283..290d8be9 100644 --- a/src/renderer/components/WorkspaceQueryTable.vue +++ b/src/renderer/components/WorkspaceQueryTable.vue @@ -123,8 +123,11 @@ export default { primaryField () { return this.fields.filter(field => ['pri', 'uni'].includes(field.key))[0] || false; }, + isHardSort () { + return this.mode === 'table' && this.localResults.length === 1000; + }, sortedResults () { - if (this.currentSort) { + if (this.currentSort && !this.isHardSort) { return [...this.localResults].sort((a, b) => { let modifier = 1; const valA = typeof a[this.currentSort] === 'string' ? a[this.currentSort].toLowerCase() : a[this.currentSort]; @@ -228,7 +231,7 @@ export default { return row[primaryFieldName]; }, setLocalResults () { - this.resetSort(); + // this.resetSort(); this.localResults = this.resultsWithRows[this.resultsetIndex] && this.resultsWithRows[this.resultsetIndex].rows ? this.resultsWithRows[this.resultsetIndex].rows.map(item => { return { ...item, _id: uidGen() }; @@ -342,6 +345,9 @@ export default { this.currentSortDir = 'asc'; this.currentSort = field; } + + if (this.isHardSort) + this.$emit('hard-sort', { field: this.currentSort, dir: this.currentSortDir }); }, resetSort () { this.currentSort = ''; diff --git a/src/renderer/components/WorkspaceTableTab.vue b/src/renderer/components/WorkspaceTableTab.vue index c72513c1..1bae6591 100644 --- a/src/renderer/components/WorkspaceTableTab.vue +++ b/src/renderer/components/WorkspaceTableTab.vue @@ -63,6 +63,7 @@ mode="table" @update-field="updateField" @delete-selected="deleteSelected" + @hard-sort="hardSort" />