Skip to content

Commit

Permalink
fix(gridMenu): command "Togge Filter" disappeared, fixes #438 (#448)
Browse files Browse the repository at this point in the history
- this command "Toggle Filter Row" disappeared if it happens to have the filter row hidden when calling translate. This PR fixes it but while fixing this, it was also found that the Filter row MUST be visible BEFORE calling the translation service else the filters don't get recreated and that is even worst.

Co-authored-by: Ghislain Beaulac <ghislain.beaulac@se.com>
  • Loading branch information
ghiscoding and ghiscoding-SE authored May 6, 2020
1 parent 06f5dc9 commit b10c5be
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
this.subscriptions.push(
this.translate.onLangChange.subscribe(() => {
if (gridOptions.enableTranslate) {
if (!this._hideHeaderRowAfterPageLoad) {
// before translating, make sure the filter row is visible to avoid having other problems,
// because if it's not shown prior to translating then the filters won't be recreated after translating
this.grid.setHeaderRowVisibility(true);
}
this.extensionService.translateCellMenu();
this.extensionService.translateColumnHeaders();
this.extensionService.translateColumnPicker();
Expand Down Expand Up @@ -768,6 +773,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
// if that is the case, we need to hide the headerRow ONLY AFTER all filters got created & dataView exist
if (this._hideHeaderRowAfterPageLoad) {
this.showHeaderRow(false);
this.sharedService.hideHeaderRowAfterPageLoad = this._hideHeaderRowAfterPageLoad;
}

// after the DataView is created & updated execute some processes
Expand Down Expand Up @@ -936,6 +942,8 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
if (!options.enableFiltering && options.enablePagination && this._isLocalGrid) {
options.enableFiltering = true;
options.showHeaderRow = false;
this._hideHeaderRowAfterPageLoad = true;
this.sharedService.hideHeaderRowAfterPageLoad = true;
}
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class GridMenuExtension implements Extension {
const backendApi = this.sharedService.gridOptions.backendServiceApi || null;
const gridMenuCustomItems: Array<GridMenuItem | 'divider'> = [];

if (this.sharedService.gridOptions && (this.sharedService.gridOptions.enableFiltering && this.sharedService.gridOptions.showHeaderRow)) {
if (this.sharedService.gridOptions && (this.sharedService.gridOptions.enableFiltering && !this.sharedService.hideHeaderRowAfterPageLoad)) {
// show grid menu: Clear all Filters
if (this.sharedService.gridOptions && this.sharedService.gridOptions.gridMenu && !this.sharedService.gridOptions.gridMenu.hideClearAllFiltersCommand) {
const commandName = 'clear-filter';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,14 @@ describe('Shared Service', () => {
expect(setSpy).toHaveBeenCalled();
expect(columns).toEqual(mockColumns);
});

it('should call "hideHeaderRowAfterPageLoad" GETTER and expect a boolean value to be returned', () => {
const flag = service.hideHeaderRowAfterPageLoad;
expect(flag).toEqual(false);
});

it('should call "hideHeaderRowAfterPageLoad" GETTER and SETTER expect same value to be returned', () => {
service.hideHeaderRowAfterPageLoad = true;
expect(service.hideHeaderRowAfterPageLoad).toEqual(true);
});
});
10 changes: 10 additions & 0 deletions src/app/modules/angular-slickgrid/services/shared.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class SharedService {
private _grid: any;
private _gridOptions: GridOption;
private _currentPagination: CurrentPagination;
private _hideHeaderRowAfterPageLoad = false;
private _visibleColumns: Column[];
onColumnsChanged = new Subject<Column[]>();

Expand Down Expand Up @@ -76,6 +77,15 @@ export class SharedService {
this._groupItemMetadataProvider = groupItemMetadataProvider;
}

/** Getter to know if user want to hide header row after 1st page load */
get hideHeaderRowAfterPageLoad(): boolean {
return this._hideHeaderRowAfterPageLoad;
}
/** Setter for knowing if user want to hide header row after 1st page load */
set hideHeaderRowAfterPageLoad(hideHeaderRowAfterPageLoad: boolean) {
this._hideHeaderRowAfterPageLoad = hideHeaderRowAfterPageLoad;
}

/** Getter for the Visible Columns in the grid */
get visibleColumns(): Column[] {
return this._visibleColumns;
Expand Down

0 comments on commit b10c5be

Please sign in to comment.