Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/app/examples/grid-state.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ export class GridStateComponent implements OnInit, OnDestroy {
hideForceFitButton: true
},
gridMenu: {
hideForceFitButton: true
hideForceFitButton: true,
hideClearFrozenColumnsCommand: false,
},
headerMenu: {
hideFreezeColumnsCommand: false,
},
enablePagination: true,
pagination: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
SortService,
TreeDataService,
} from '../../services';
import { Column, CurrentFilter, CurrentSorter, GraphqlPaginatedResult, GraphqlServiceApi, GraphqlServiceOption, GridOption, GridState, GridStateChange, GridStateType, Pagination, ServicePagination } from '../../models';
import { Column, CurrentFilter, CurrentPinning, CurrentSorter, GraphqlPaginatedResult, GraphqlServiceApi, GraphqlServiceOption, GridOption, GridState, GridStateChange, GridStateType, Pagination, ServicePagination } from '../../models';
import { Filters } from '../../filters';
import { Editors } from '../../editors';
import * as utilities from '../../services/backend-utilities';
Expand Down Expand Up @@ -847,6 +847,15 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
expect(backendSpy).toHaveBeenCalledWith(mockColumnFilter, false);
});

it('should override frozen grid options when "pinning" is defined in the "presets" property', () => {
const pinningMock = { frozenBottom: false, frozenColumn: -1, frozenRow: -1 } as CurrentPinning;

component.gridOptions.presets = { pinning: pinningMock };
component.ngAfterViewInit();

expect(component.gridOptions).toEqual({ ...component.gridOptions, ...pinningMock });
});

it('should call the "updateFilters" method when filters are defined in the "presets" property', () => {
const spy = jest.spyOn(mockGraphqlService, 'updateFilters');
const mockFilters = [{ columnId: 'company', searchTerms: ['xyz'], operator: 'IN' }] as CurrentFilter[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,11 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
this.sharedService.visibleColumns = this._columnDefinitions;
this.extensionService.createExtensionsBeforeGridCreation(this._columnDefinitions, this.gridOptions);

// if user entered some Pinning/Frozen "presets", we need to apply them in the grid options
if (this.gridOptions.presets?.pinning) {
this.gridOptions = { ...this.gridOptions, ...this.gridOptions.presets.pinning };
}

// build SlickGrid Grid, also user might optionally pass a custom dataview (e.g. remote model)
this.grid = new Slick.Grid(`#${this.gridId}`, this.customDataView || this.dataView, this._columnDefinitions, this.gridOptions);

Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/angular-slickgrid/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Constants {
TEXT_CLEAR_ALL_FILTERS: 'Clear all Filters',
TEXT_CLEAR_ALL_GROUPING: 'Clear all Grouping',
TEXT_CLEAR_ALL_SORTING: 'Clear all Sorting',
TEXT_CLEAR_FROZEN_COLUMNS: 'Clear Frozen Columns',
TEXT_CLEAR_PINNING: 'Unfreeze Columns/Rows',
TEXT_COLLAPSE_ALL_GROUPS: 'Collapse all Groups',
TEXT_CONTAINS: 'Contains',
TEXT_COLUMNS: 'Columns',
Expand Down

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,17 @@ export class GridMenuExtension implements Extension {
const gridOptions = this.sharedService.gridOptions;
const translationPrefix = getTranslationPrefix(gridOptions);

// show grid menu: Clear Frozen Columns
// show grid menu: Unfreeze Columns/Rows
if (this.sharedService.gridOptions && this._gridMenuOptions && !this._gridMenuOptions.hideClearFrozenColumnsCommand) {
const commandName = 'clear-frozen-columns';
const commandName = 'clear-pinning';
if (!originalCustomItems.find(item => item !== 'divider' && item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconClearFrozenColumnsCommand || 'fa fa-times',
title: this.sharedService.gridOptions.enableTranslate ? this.translate.instant(`${translationPrefix}CLEAR_FROZEN_COLUMNS`) : this._locales && this._locales.TEXT_CLEAR_FROZEN_COLUMNS,
title: this.sharedService.gridOptions.enableTranslate ? this.translate.instant(`${translationPrefix}CLEAR_PINNING`) : this._locales && this._locales.TEXT_CLEAR_PINNING,
disabled: false,
command: commandName,
positionOrder: 49
positionOrder: 52
}
);
}
Expand Down Expand Up @@ -259,7 +259,7 @@ export class GridMenuExtension implements Extension {
title: this.sharedService.gridOptions.enableTranslate ? this.translate.instant(`${translationPrefix}TOGGLE_FILTER_ROW`) : this._locales && this._locales.TEXT_TOGGLE_FILTER_ROW,
disabled: false,
command: commandName,
positionOrder: 52
positionOrder: 53
}
);
}
Expand All @@ -275,7 +275,7 @@ export class GridMenuExtension implements Extension {
title: this.sharedService.gridOptions.enableTranslate ? this.translate.instant(`${translationPrefix}REFRESH_DATASET`) : this._locales && this._locales.TEXT_REFRESH_DATASET,
disabled: false,
command: commandName,
positionOrder: 56
positionOrder: 57
}
);
}
Expand All @@ -293,7 +293,7 @@ export class GridMenuExtension implements Extension {
title: this.sharedService.gridOptions.enableTranslate ? this.translate.instant(`${translationPrefix}TOGGLE_PRE_HEADER_ROW`) : this._locales && this._locales.TEXT_TOGGLE_PRE_HEADER_ROW,
disabled: false,
command: commandName,
positionOrder: 52
positionOrder: 53
}
);
}
Expand Down Expand Up @@ -328,7 +328,7 @@ export class GridMenuExtension implements Extension {
title: this.sharedService.gridOptions.enableTranslate ? this.translate.instant(`${translationPrefix}EXPORT_TO_CSV`) : this._locales && this._locales.TEXT_EXPORT_TO_CSV,
disabled: false,
command: commandName,
positionOrder: 53
positionOrder: 54
}
);
}
Expand All @@ -344,7 +344,7 @@ export class GridMenuExtension implements Extension {
title: this.sharedService.gridOptions.enableTranslate ? this.translate.instant(`${translationPrefix}EXPORT_TO_EXCEL`) : this._locales && this._locales.TEXT_EXPORT_TO_EXCEL,
disabled: false,
command: commandName,
positionOrder: 54
positionOrder: 55
}
);
}
Expand All @@ -360,7 +360,7 @@ export class GridMenuExtension implements Extension {
title: this.sharedService.gridOptions.enableTranslate ? this.translate.instant(`${translationPrefix}EXPORT_TO_TAB_DELIMITED`) : this._locales && this._locales.TEXT_EXPORT_TO_TAB_DELIMITED,
disabled: false,
command: commandName,
positionOrder: 55
positionOrder: 56
}
);
}
Expand All @@ -383,15 +383,25 @@ export class GridMenuExtension implements Extension {
private executeGridMenuInternalCustomCommands(e: Event, args: GridMenuItem) {
if (args && args.command) {
switch (args.command) {
case 'clear-frozen-columns':
case 'clear-pinning':
const visibleColumns = [...this.sharedService.visibleColumns];
this.sharedService.grid.setOptions({ frozenColumn: -1, enableMouseWheelScrollHandler: false });
const newGridOptions = { frozenColumn: -1, frozenRow: -1, frozenBottom: false, enableMouseWheelScrollHandler: false };
this.sharedService.grid.setOptions(newGridOptions);
this.sharedService.gridOptions.frozenColumn = newGridOptions.frozenColumn;
this.sharedService.gridOptions.frozenRow = newGridOptions.frozenRow;
this.sharedService.gridOptions.frozenBottom = newGridOptions.frozenBottom;
this.sharedService.gridOptions.enableMouseWheelScrollHandler = newGridOptions.enableMouseWheelScrollHandler;

// SlickGrid seems to be somehow resetting the columns to their original positions,
// so let's re-fix them to the position we kept as reference
if (Array.isArray(visibleColumns)) {
this.sharedService.grid.setColumns(visibleColumns);
}

// we also need to autosize columns if the option is enabled
if (this.sharedService.gridOptions.enableAutoSizeColumns) {
this.sharedService.grid.autosizeColumns();
}
break;
case 'clear-filter':
this.filterService.clearFilters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,22 @@ export class HeaderMenuExtension implements Extension {
case 'freeze-columns':
const visibleColumns = [...this.sharedService.visibleColumns];
const columnPosition = visibleColumns.findIndex((col) => col.id === args.column.id);
this.sharedService.grid.setOptions({ frozenColumn: columnPosition, enableMouseWheelScrollHandler: true } as GridOption);
const newGridOptions = { frozenColumn: columnPosition, enableMouseWheelScrollHandler: true };
this.sharedService.grid.setOptions(newGridOptions);
this.sharedService.gridOptions.frozenColumn = newGridOptions.frozenColumn;
this.sharedService.gridOptions.enableMouseWheelScrollHandler = newGridOptions.enableMouseWheelScrollHandler;
this.sharedService.frozenVisibleColumnId = args.column.id;

// to freeze columns, we need to take only the visible columns and we also need to use setColumns() when some of them are hidden
// to make sure that we only use the visible columns, not doing this will have the undesired effect of showing back some of the hidden columns
if (this.sharedService.hasColumnsReordered || (Array.isArray(this.sharedService.allColumns) && visibleColumns.length !== this.sharedService.allColumns.length)) {
this.sharedService.grid.setColumns(visibleColumns);
}

// we also need to autosize columns if the option is enabled
if (this.sharedService.gridOptions.enableAutoSizeColumns) {
this.sharedService.grid.autosizeColumns();
}
break;
case 'sort-asc':
case 'sort-desc':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface CurrentPinning {
/** Defaults to false, do we want to freeze (pin) the bottom portion instead of the top */
frozenBottom?: boolean;

/** Number of column index(es) to freeze (pin) in the grid */
frozenColumn?: number;

/** Number of row index(es) to freeze (pin) in the grid */
frozenRow?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface GridMenu {
/** Defaults to false, which will hide the "Clear all Sorting" command in the Grid Menu (Grid Option "enableSorting: true" has to be enabled) */
hideClearAllSortingCommand?: boolean;

/** Defaults to true, which will hide the "Clear Frozen Columns" command in the Grid Menu */
/** Defaults to true, which will hide the "Unfreeze Columns/Rows" command in the Grid Menu */
hideClearFrozenColumnsCommand?: boolean;

/** Defaults to false, which will hide the "Export to CSV" command in the Grid Menu (Grid Option "enableExport: true" has to be enabled) */
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface GridMenu {
/** icon for the "Clear all Sorting" command */
iconClearAllSortingCommand?: string;

/** icon for the "Clear Frozen Columns" command */
/** icon for the "Unfreeze Columns/Rows" command */
iconClearFrozenColumnsCommand?: string;

/** icon for the "Export to CSV" command */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ export interface GridOption {
/** Defaults to false, do we want to freeze (pin) the bottom portion instead of the top */
frozenBottom?: boolean;

/** Number of column(s) to freeze (pin) in the grid */
/** Number of column index(es) to freeze (pin) in the grid */
frozenColumn?: number;

/** Number of row(s) to freeze (pin) in the grid */
/** Number of row index(es) to freeze (pin) in the grid */
frozenRow?: number;

/** Defaults to false, which leads to have row with full width */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CurrentColumn, CurrentFilter, CurrentPagination, CurrentRowSelection, CurrentSorter } from './index';
import { CurrentColumn, CurrentFilter, CurrentPagination, CurrentPinning, CurrentRowSelection, CurrentSorter } from './index';

export interface GridState {
/** Columns (and their state: visibility/position) that are currently applied in the grid */
Expand All @@ -13,6 +13,9 @@ export interface GridState {
/** Pagination (and it's state, pageNumber, pageSize) that are currently applied in the grid */
pagination?: CurrentPagination | null;

/** Pinning (frozen) column & row position */
pinning?: CurrentPinning;

/** Row Selections (by their dataContext IDs and/or grid row indexes) */
rowSelection?: CurrentRowSelection | null;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CurrentColumn, CurrentFilter, CurrentPagination, CurrentRowSelection, CurrentSorter, GridState, GridStateType } from './index';
import { CurrentColumn, CurrentFilter, CurrentPagination, CurrentPinning, CurrentRowSelection, CurrentSorter, GridState, GridStateType } from './index';

export interface GridStateChange {
/** Last Grid State Change that was triggered (only 1 type of change at a time) */
change?: {
/** Grid State change, the values of the new change */
newValues: CurrentColumn[] | CurrentFilter[] | CurrentSorter[] | CurrentPagination | CurrentRowSelection;
newValues: CurrentColumn[] | CurrentFilter[] | CurrentSorter[] | CurrentPagination | CurrentPinning | CurrentRowSelection;

/** The Grid State Type of change that was made (filter/sorter/...) */
type: GridStateType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum GridStateType {
columns = 'columns',
filter = 'filter',
pagination = 'pagination',
pinning = 'pinning',
sorter = 'sorter',
rowSelection = 'rowSelection',
}
1 change: 1 addition & 0 deletions src/app/modules/angular-slickgrid/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from './contextMenu.interface';
export * from './currentColumn.interface';
export * from './currentFilter.interface';
export * from './currentPagination.interface';
export * from './currentPinning.interface';
export * from './currentRowSelection.interface';
export * from './currentSorter.interface';
export * from './customFooterOption.interface';
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/angular-slickgrid/models/locale.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export interface Locale {
/** Text "Clear all Sorting" shown in Header Menu */
TEXT_CLEAR_ALL_SORTING: string;

/** Text "Clear Frozen Columns" shown in Grid Menu */
TEXT_CLEAR_FROZEN_COLUMNS: string;
/** Text "Unfreeze Columns/Rows" shown in Grid Menu */
TEXT_CLEAR_PINNING: string;

/** Text "Columns" title displayed in the Column Picker & Grid Menu (when enabled) */
TEXT_COLUMNS: string;
Expand Down
Loading