From e9d97018187ae9bf86b0b6e8e7d55f31754f2093 Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 12 Jun 2024 13:11:05 +0200 Subject: [PATCH] Get hide columns working --- js/core/transform.ts | 7 ++++++- js/core/transformExecutors.ts | 5 +++++ js/core/transformStateManager.ts | 12 ++++++++++-- js/core/viewbasedjsonmodel.ts | 2 -- js/feathergrid.ts | 23 +++++++++++++++-------- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/js/core/transform.ts b/js/core/transform.ts index 4f7fbd95..dff659ab 100644 --- a/js/core/transform.ts +++ b/js/core/transform.ts @@ -38,10 +38,15 @@ export namespace Transform { */ export type Hide = { /** - * A type alias for this trasformation. + * A type alias for this transformation. */ type: 'hide'; + /** + * The column in the data schema to apply the transformation to. + */ + column: string; + /** * The column in the data schema to apply the transformation to. */ diff --git a/js/core/transformExecutors.ts b/js/core/transformExecutors.ts index dabe8c8e..c505a2b7 100644 --- a/js/core/transformExecutors.ts +++ b/js/core/transformExecutors.ts @@ -64,6 +64,11 @@ export namespace HideExecutor { */ field: string; + /** + * The data type of the column associated with this transform. + */ + dType: string; + /** * Boolean indicating if all columns should be hidden */ diff --git a/js/core/transformStateManager.ts b/js/core/transformStateManager.ts index 5d9fde08..df05ab90 100644 --- a/js/core/transformStateManager.ts +++ b/js/core/transformStateManager.ts @@ -44,7 +44,7 @@ export class TransformStateManager { this._state[transform.column]['filter'] = transform; break; case 'hide': - this._state[transform.columnIndex]['hide'] = transform; + this._state[transform.column]['hide'] = transform; break; default: throw 'unreachable'; @@ -153,8 +153,16 @@ export class TransformStateManager { filterExecutors.push(executor); } if (transform.hide) { + let dType = ''; + for (const field of data.schema.fields) { + if (field.name === transform.hide.column) { + dType = field.type; + } + } + const executor = new HideExecutor({ - field: data.schema.fields[transform.hide.columnIndex]['name'], + field: transform.hide.column, + dType, hideAll: transform.hide.hideAll, }); hideExecutors.push(executor); diff --git a/js/core/viewbasedjsonmodel.ts b/js/core/viewbasedjsonmodel.ts index 8dcf0a1a..5e335b36 100644 --- a/js/core/viewbasedjsonmodel.ts +++ b/js/core/viewbasedjsonmodel.ts @@ -76,7 +76,6 @@ export class ViewBasedJSONModel extends MutableDataModel { */ updateDataset(data: DataSource): void { this._dataset = data; - // does not happen when selecting hide column this._updatePrimaryKeyMap(); const view = new View(this._dataset); this.currentView = view; @@ -567,7 +566,6 @@ export class ViewBasedJSONModel extends MutableDataModel { } // We need to rerun the transforms, as the changed cells may change the order // or visibility of other rows - console.log('update row value'); this.currentView = this._transformState.createView(this._dataset); } diff --git a/js/feathergrid.ts b/js/feathergrid.ts index d31f0306..538cb12d 100644 --- a/js/feathergrid.ts +++ b/js/feathergrid.ts @@ -1074,14 +1074,20 @@ export class FeatherGrid extends Widget { label: 'Hide Column', mnemonic: -1, execute: (args) => { - const cellClick: FeatherGridContextMenu.CommandArgs = + const command: FeatherGridContextMenu.CommandArgs = args as FeatherGridContextMenu.CommandArgs; + const colIndex = this._dataModel.getSchemaIndex( - cellClick.region, - cellClick.columnIndex, + command.region, + command.columnIndex, ); + + const column = + this.dataModel.currentView.dataset.schema.fields[colIndex]; + this._dataModel.addTransform({ type: 'hide', + column: column.name, columnIndex: colIndex, hideAll: false, }); @@ -1097,8 +1103,13 @@ export class FeatherGrid extends Widget { cellClick.region, cellClick.columnIndex, ); + + const column = + this.dataModel.currentView.dataset.schema.fields[colIndex]; + this._dataModel.addTransform({ type: 'hide', + column: column.name, columnIndex: colIndex, hideAll: true, }); @@ -1110,14 +1121,10 @@ export class FeatherGrid extends Widget { execute: () => { const activeTransforms: Transform.TransformSpec[] = this._dataModel.activeTransforms; - console.log( - 'this._dataModel.activeTransforms', - this._dataModel.activeTransforms, - ); + const newTransforms = activeTransforms.filter( (val) => val.type !== 'hide', ); - console.log('newTransforms', newTransforms); this._dataModel.replaceTransforms(newTransforms); }, });