mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 16:16:02 +00:00
datagrid column manager, hide columns
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
|
||||
export default interface GridConfig {
|
||||
hiddenColumns: number[];
|
||||
hiddenColumns: string[];
|
||||
}
|
||||
|
||||
@@ -1,14 +1,38 @@
|
||||
import GridConfig from "./GridConfig";
|
||||
import _ from 'lodash';
|
||||
import GridConfig from './GridConfig';
|
||||
import { ForeignKeyInfo } from '@dbgate/types';
|
||||
|
||||
export interface DisplayColumn {
|
||||
columnName: string;
|
||||
headerText: string;
|
||||
uniqueName: string;
|
||||
uniquePath: string[];
|
||||
notNull: boolean;
|
||||
autoIncrement: boolean;
|
||||
isPrimaryKey: boolean;
|
||||
foreignKey: ForeignKeyInfo;
|
||||
isChecked: boolean;
|
||||
}
|
||||
|
||||
export default abstract class GridDisplay {
|
||||
constructor(
|
||||
public config: GridConfig,
|
||||
protected setConfig: (configh: GridConfig) => void
|
||||
) {}
|
||||
constructor(public config: GridConfig, protected setConfig: (config: GridConfig) => void) {}
|
||||
abstract getPageQuery(offset: number, count: number): string;
|
||||
columns: DisplayColumn[];
|
||||
setColumnVisibility(uniqueName, isVisible) {
|
||||
if (isVisible) {
|
||||
this.setConfig({
|
||||
...this.config,
|
||||
hiddenColumns: (this.config.hiddenColumns || []).filter(x => x != uniqueName),
|
||||
});
|
||||
} else {
|
||||
this.setConfig({
|
||||
...this.config,
|
||||
hiddenColumns: [...(this.config.hiddenColumns || []), uniqueName],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get hiddenColumnIndexes() {
|
||||
return (this.config.hiddenColumns || []).map(x => _.findIndex(this.columns, y => y.uniqueName == x));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,19 @@ export default class TableGridDisplay extends GridDisplay {
|
||||
public table: TableInfo,
|
||||
public driver: EngineDriver,
|
||||
config: GridConfig,
|
||||
setConfig: (configh: GridConfig) => void
|
||||
setConfig: (config: GridConfig) => void
|
||||
) {
|
||||
super(config, setConfig);
|
||||
this.columns = table.columns;
|
||||
this.columns = table.columns.map(col => ({
|
||||
...col,
|
||||
headerText: col.columnName,
|
||||
uniqueName: col.columnName,
|
||||
uniquePath: [col.columnName],
|
||||
isPrimaryKey: table.primaryKey && !!table.primaryKey.columns.find(x => x.columnName == col.columnName),
|
||||
foreignKey:
|
||||
table.foreignKeys && table.foreignKeys.find(fk => fk.columns.find(x => x.columnName == col.columnName)),
|
||||
isChecked: !(config.hiddenColumns && config.hiddenColumns.includes(col.columnName)),
|
||||
}));
|
||||
}
|
||||
|
||||
createSelect() {
|
||||
@@ -19,7 +28,7 @@ export default class TableGridDisplay extends GridDisplay {
|
||||
const select: Select = {
|
||||
commandType: 'select',
|
||||
from: { name: this.table },
|
||||
columns: this.table.columns.map(col => ({ exprType: 'column', ...col })),
|
||||
columns: this.table.columns.map(col => ({ exprType: 'column', alias: col.columnName, ...col })),
|
||||
orderBy: [
|
||||
{
|
||||
exprType: 'column',
|
||||
|
||||
Reference in New Issue
Block a user