mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 19:16:01 +00:00
grid sorting
This commit is contained in:
@@ -9,6 +9,10 @@ export interface GridConfigColumns {
|
||||
|
||||
export interface GridConfig extends GridConfigColumns {
|
||||
filters: { [uniqueName: string]: string };
|
||||
sort: {
|
||||
uniqueName: string;
|
||||
order: 'ASC' | 'DESC';
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface GridCache {
|
||||
@@ -22,6 +26,7 @@ export function createGridConfig(): GridConfig {
|
||||
expandedColumns: [],
|
||||
addedColumns: [],
|
||||
filters: {},
|
||||
sort: [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -307,6 +307,20 @@ export abstract class GridDisplay {
|
||||
}
|
||||
}
|
||||
|
||||
applySortOnSelect(select: Select, displayedColumnInfo: DisplayedColumnInfo) {
|
||||
if (this.config.sort?.length > 0) {
|
||||
select.orderBy = this.config.sort
|
||||
.map(col => ({ ...col, dispInfo: displayedColumnInfo[col.uniqueName] }))
|
||||
.filter(col => col.dispInfo)
|
||||
.map(col => ({
|
||||
exprType: 'column',
|
||||
columnName: col.dispInfo.columnName,
|
||||
direction: col.order,
|
||||
source: { alias: col.dispInfo.sourceAlias },
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
getDisplayColumns(table: TableInfo, parentPath: string[]) {
|
||||
return (
|
||||
table?.columns
|
||||
@@ -350,6 +364,18 @@ export abstract class GridDisplay {
|
||||
this.reload();
|
||||
}
|
||||
|
||||
setSort(uniqueName, order) {
|
||||
this.setConfig({
|
||||
...this.config,
|
||||
sort: [{ uniqueName, order }],
|
||||
});
|
||||
this.reload();
|
||||
}
|
||||
|
||||
getSortOrder(uniqueName) {
|
||||
return this.config.sort.find(x => x.uniqueName == uniqueName)?.order;
|
||||
}
|
||||
|
||||
get filterCount() {
|
||||
return _.compact(_.values(this.config.filters)).length;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ export class TableGridDisplay extends GridDisplay {
|
||||
this.addHintsToSelect(select)
|
||||
);
|
||||
this.applyFilterOnSelect(select, displayedColumnInfo);
|
||||
this.applySortOnSelect(select, displayedColumnInfo);
|
||||
if (action == 'loadRequired') {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user