Skip to content

Commit 6b6a637

Browse files
author
Greg
committed
Get hide columns working
1 parent f50f8aa commit 6b6a637

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

js/core/transform.ts

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export namespace Transform {
4242
*/
4343
type: 'hide';
4444

45+
/**
46+
* The column in the data schema to apply the transformation to.
47+
*/
48+
column: string;
49+
4550
/**
4651
* The column in the data schema to apply the transformation to.
4752
*/

js/core/transformExecutors.ts

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export namespace HideExecutor {
6464
*/
6565
field: string;
6666

67+
/**
68+
* The data type of the column associated with this transform.
69+
*/
70+
dType: string;
71+
6772
/**
6873
* Boolean indicating if all columns should be hidden
6974
*/

js/core/transformStateManager.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class TransformStateManager {
4444
this._state[transform.column]['filter'] = transform;
4545
break;
4646
case 'hide':
47-
this._state[transform.columnIndex]['hide'] = transform;
47+
this._state[transform.column]['hide'] = transform;
4848
break;
4949
default:
5050
throw 'unreachable';
@@ -153,8 +153,16 @@ export class TransformStateManager {
153153
filterExecutors.push(executor);
154154
}
155155
if (transform.hide) {
156+
let dType = '';
157+
for (const field of data.schema.fields) {
158+
if (field.name === transform.hide.column) {
159+
dType = field.type;
160+
}
161+
}
162+
156163
const executor = new HideExecutor({
157-
field: data.schema.fields[transform.hide.columnIndex]['name'],
164+
field: transform.hide.column,
165+
dType,
158166
hideAll: transform.hide.hideAll,
159167
});
160168
hideExecutors.push(executor);

js/core/viewbasedjsonmodel.ts

-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export class ViewBasedJSONModel extends MutableDataModel {
7676
*/
7777
updateDataset(data: DataSource): void {
7878
this._dataset = data;
79-
// does not happen when selecting hide column
8079
this._updatePrimaryKeyMap();
8180
const view = new View(this._dataset);
8281
this.currentView = view;
@@ -567,7 +566,6 @@ export class ViewBasedJSONModel extends MutableDataModel {
567566
}
568567
// We need to rerun the transforms, as the changed cells may change the order
569568
// or visibility of other rows
570-
console.log('update row value');
571569
this.currentView = this._transformState.createView(this._dataset);
572570
}
573571

js/feathergrid.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -1074,14 +1074,20 @@ export class FeatherGrid extends Widget {
10741074
label: 'Hide Column',
10751075
mnemonic: -1,
10761076
execute: (args) => {
1077-
const cellClick: FeatherGridContextMenu.CommandArgs =
1077+
const command: FeatherGridContextMenu.CommandArgs =
10781078
args as FeatherGridContextMenu.CommandArgs;
1079+
10791080
const colIndex = this._dataModel.getSchemaIndex(
1080-
cellClick.region,
1081-
cellClick.columnIndex,
1081+
command.region,
1082+
command.columnIndex,
10821083
);
1084+
1085+
const column =
1086+
this.dataModel.currentView.dataset.schema.fields[colIndex];
1087+
10831088
this._dataModel.addTransform({
10841089
type: 'hide',
1090+
column: column.name,
10851091
columnIndex: colIndex,
10861092
hideAll: false,
10871093
});
@@ -1097,8 +1103,13 @@ export class FeatherGrid extends Widget {
10971103
cellClick.region,
10981104
cellClick.columnIndex,
10991105
);
1106+
1107+
const column =
1108+
this.dataModel.currentView.dataset.schema.fields[colIndex];
1109+
11001110
this._dataModel.addTransform({
11011111
type: 'hide',
1112+
column: column.name,
11021113
columnIndex: colIndex,
11031114
hideAll: true,
11041115
});
@@ -1110,14 +1121,10 @@ export class FeatherGrid extends Widget {
11101121
execute: () => {
11111122
const activeTransforms: Transform.TransformSpec[] =
11121123
this._dataModel.activeTransforms;
1113-
console.log(
1114-
'this._dataModel.activeTransforms',
1115-
this._dataModel.activeTransforms,
1116-
);
1124+
11171125
const newTransforms = activeTransforms.filter(
11181126
(val) => val.type !== 'hide',
11191127
);
1120-
console.log('newTransforms', newTransforms);
11211128
this._dataModel.replaceTransforms(newTransforms);
11221129
},
11231130
});

0 commit comments

Comments
 (0)