diff --git a/projects/extensions/grid/column-menu.html b/projects/extensions/grid/column-menu.html index b555461b..c308a9ef 100755 --- a/projects/extensions/grid/column-menu.html +++ b/projects/extensions/grid/column-menu.html @@ -120,7 +120,7 @@ + (change)="_handleChecked(col)"> {{col.header | toObservable | async}} diff --git a/projects/extensions/grid/column-menu.ts b/projects/extensions/grid/column-menu.ts index 31c347d3..7ed47029 100755 --- a/projects/extensions/grid/column-menu.ts +++ b/projects/extensions/grid/column-menu.ts @@ -9,7 +9,6 @@ import { ViewChild, ViewEncapsulation, } from '@angular/core'; -import { MatCheckboxChange } from '@angular/material/checkbox'; import { ThemePalette } from '@angular/material/core'; import { MatMenu, MatMenuTrigger } from '@angular/material/menu'; import { @@ -81,7 +80,12 @@ export class MtxGridColumnMenu { this.columnChange.emit(this.columns); } - _handleChecked(e: MatCheckboxChange) { + _handleChecked(col: MtxGridColumn) { + if (this.selectableChecked === 'show') { + col.hide = !col.show; + } else { + col.show = !col.hide; + } this.columnChange.emit(this.columns); } diff --git a/projects/extensions/grid/grid-pipes.ts b/projects/extensions/grid/grid-pipes.ts index 507a8a1d..75c726d7 100644 --- a/projects/extensions/grid/grid-pipes.ts +++ b/projects/extensions/grid/grid-pipes.ts @@ -24,11 +24,11 @@ export class MtxGridColClassPipe implements PipeTransform { export class MtxGridRowClassPipe implements PipeTransform { transform( rowData: Record, - index: number, + index: number | undefined, dataIndex: number, rowClassFormatter?: MtxGridRowClassFormatter ) { - const rowIndex = typeof index === 'undefined' ? dataIndex : index; + const rowIndex = index === undefined ? dataIndex : index; const classList: string[] = rowIndex % 2 === 1 ? ['mat-row-odd'] : []; if (rowClassFormatter) { for (const key of Object.keys(rowClassFormatter)) { diff --git a/projects/extensions/grid/grid.ts b/projects/extensions/grid/grid.ts index 42ddb18a..b3ea4d42 100755 --- a/projects/extensions/grid/grid.ts +++ b/projects/extensions/grid/grid.ts @@ -333,19 +333,22 @@ export class MtxGrid implements OnChanges, AfterViewInit, OnDestroy { return this._utils.getColData(data, colDef); } + _isColumnHide(item: MtxGridColumn) { + return item.hide !== undefined ? item.hide : item.show !== undefined ? !item.show : false; + } + // Waiting for async data ngOnChanges(changes: SimpleChanges) { this._countPinnedPosition(); - this.displayedColumns = this.columns.filter(item => !item.hide).map(item => item.field); + this.displayedColumns = this.columns + .filter(item => !this._isColumnHide(item)) + .map(item => item.field); if (this.showColumnMenuButton) { this.columns.forEach(item => { - if (this.columnHideableChecked === 'show') { - item.show = !item.hide; - } else { - item.hide = !!item.hide; - } + item.hide = this._isColumnHide(item); + item.show = !item.hide; }); } @@ -415,8 +418,8 @@ export class MtxGrid implements OnChanges, AfterViewInit, OnDestroy { }); } - _getIndex(index: number, dataIndex: number) { - return typeof index === 'undefined' ? dataIndex : index; + _getIndex(index: number | undefined, dataIndex: number) { + return index === undefined ? dataIndex : index; } _onSortChange(sort: Sort) {