Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 9137dc1

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
latest version of Slickgrid fixes missing picker i18n titles
1 parent 391a399 commit 9137dc1

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
138138
this.translate.onLangChange.subscribe((event) => {
139139
if (options.enableTranslate) {
140140
this.controlAndPluginService.translateHeaders();
141+
this.controlAndPluginService.translateColumnPicker();
141142
this.controlAndPluginService.translateGridMenu();
142143
}
143144
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface ColumnPicker {
2+
columnTitle?: string;
3+
forceFitTitle?: string;
4+
syncResizeTitle?: string;
5+
}

src/app/modules/angular-slickgrid/models/gridMenu.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface GridMenu {
66
iconImage?: string;
77
iconCssClass?: string;
88
leaveOpen?: boolean;
9+
forceFitTitle?: string;
10+
syncResizeTitle?: string;
911
menuWidth?: number;
1012
resizeOnShowHeaderRow?: boolean;
1113
customItems?: CustomGridMenu[];

src/app/modules/angular-slickgrid/models/gridOption.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AutoResizeOption } from './autoResizeOption.interface';
22
import { BackendEventChanged } from './backendEventChanged.interface';
3+
import { ColumnPicker } from './columnPicker.interface';
34
import { CheckboxSelector } from './checkboxSelector.interface';
45
import { GridMenu } from './gridMenu.interface';
56
import { HeaderButton } from './headerButton.interface';
@@ -20,6 +21,7 @@ export interface GridOption {
2021
};
2122
cellHighlightCssClass?: string | null;
2223
checkboxSelector?: CheckboxSelector;
24+
columnPicker?: ColumnPicker;
2325
editable?: boolean;
2426
enableAsyncPostRender?: boolean;
2527
enableAutoResize?: boolean;

src/app/modules/angular-slickgrid/services/controlAndPlugin.service.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class ControlAndPluginService {
5353
this.visibleColumns = columnDefinitions;
5454

5555
if (options.enableColumnPicker) {
56-
this.columnPickerControl = new Slick.Controls.ColumnPicker(columnDefinitions, grid, options);
56+
this.columnPickerControl = this.createColumnPicker(grid, columnDefinitions, options);
5757
}
5858
if (options.enableGridMenu) {
5959
this.gridMenuControl = this.createGridMenu(grid, columnDefinitions, options);
@@ -112,6 +112,18 @@ export class ControlAndPluginService {
112112
}
113113
}
114114

115+
createColumnPicker(grid: any, columnDefinitions: Column[], options: GridOption) {
116+
// localization support for the picker
117+
const forceFitTitle = options.enableTranslate ? this.translate.instant('FORCE_FIT_COLUMNS') : 'Force fit columns';
118+
const syncResizeTitle = options.enableTranslate ? this.translate.instant('SYNCHRONOUS_RESIZE') : 'Synchronous resize';
119+
120+
options.columnPicker = options.columnPicker || {};
121+
options.columnPicker.forceFitTitle = options.columnPicker.forceFitTitle || forceFitTitle;
122+
options.columnPicker.syncResizeTitle = options.columnPicker.syncResizeTitle || syncResizeTitle;
123+
124+
this.columnPickerControl = new Slick.Controls.ColumnPicker(columnDefinitions, grid, options);
125+
}
126+
115127
createGridMenu(grid: any, columnDefinitions: Column[], options: GridOption) {
116128
this.prepareGridMenu(grid, options);
117129

@@ -120,23 +132,6 @@ export class ControlAndPluginService {
120132
gridMenuControl.onBeforeMenuShow.subscribe((e: Event, args: CellArgs) => {
121133
if (options.gridMenu && typeof options.gridMenu.onBeforeMenuShow === 'function') {
122134
options.gridMenu.onBeforeMenuShow(e, args);
123-
} else {
124-
// when using i18n with Grid Menu, we have a problem with the last 2 checkbox
125-
// they are written in plain English within the SlickGrid Controls
126-
// and so we don't have access directly to their text, however with a jQuery hack,
127-
// we can somehow change the text with jQuery but it's very patchy
128-
if (options.enableTranslate) {
129-
setTimeout(() => {
130-
const forceFitElm = $(`label:contains('Force fit columns')`);
131-
const syncResizeElm = $(`label:contains('Synchronous resize')`);
132-
if (forceFitElm && forceFitElm[0] && forceFitElm[0].lastChild && forceFitElm[0].lastChild.textContent) {
133-
forceFitElm[0].lastChild.textContent = this.translate.instant('FORCE_FIT_COLUMNS');
134-
}
135-
if (syncResizeElm && syncResizeElm[0] && syncResizeElm[0].lastChild && syncResizeElm[0].lastChild.textContent) {
136-
syncResizeElm[0].lastChild.textContent = this.translate.instant('SYNCHRONOUS_RESIZE');
137-
}
138-
}, 10);
139-
}
140135
}
141136
});
142137
gridMenuControl.onCommand.subscribe((e: Event, args: CellArgs) => {
@@ -246,7 +241,7 @@ export class ControlAndPluginService {
246241
}
247242
}
248243

249-
// add the custom command title if there's no command
244+
// add the custom command title if there are commands
250245
if (options && options.gridMenu && options.gridMenu.customItems && options.gridMenu.customItems.length > 0) {
251246
const customTitle = options.enableTranslate ? this.translate.instant('COMMANDS') : 'Commands';
252247
options.gridMenu.customTitle = options.gridMenu.customTitle || customTitle;
@@ -255,9 +250,13 @@ export class ControlAndPluginService {
255250

256251
private prepareGridMenu(grid: any, options: GridOption) {
257252
const columnTitle = options.enableTranslate ? this.translate.instant('COLUMNS') : 'Columns';
253+
const forceFitTitle = options.enableTranslate ? this.translate.instant('FORCE_FIT_COLUMNS') : 'Force fit columns';
254+
const syncResizeTitle = options.enableTranslate ? this.translate.instant('SYNCHRONOUS_RESIZE') : 'Synchronous resize';
258255

259256
options.gridMenu = options.gridMenu || {};
260257
options.gridMenu.columnTitle = options.gridMenu.columnTitle || columnTitle;
258+
options.gridMenu.forceFitTitle = options.gridMenu.forceFitTitle || forceFitTitle;
259+
options.gridMenu.syncResizeTitle = options.gridMenu.syncResizeTitle || syncResizeTitle;
261260
options.gridMenu.iconCssClass = options.gridMenu.iconCssClass || 'fa fa-bars';
262261
options.gridMenu.menuWidth = options.gridMenu.menuWidth || 18;
263262
options.gridMenu.customTitle = options.gridMenu.customTitle || undefined;
@@ -266,6 +265,20 @@ export class ControlAndPluginService {
266265
// options.gridMenu.resizeOnShowHeaderRow = options.showHeaderRow;
267266
}
268267

268+
/**
269+
* Translate the Column Picker and it's last 2 checkboxes
270+
* Note that the only way that seems to work is to destroy and re-create the Column Picker
271+
* Changing only the columnPicker.columnTitle with i18n translate was not enough.
272+
*/
273+
translateColumnPicker() {
274+
// destroy and re-create the Column Picker which seems to be the only way to translate properly
275+
if (this.columnPickerControl) {
276+
this.columnPickerControl.destroy();
277+
this.columnPickerControl = null;
278+
}
279+
this._gridOptions.columnPicker = undefined;
280+
this.createColumnPicker(this._grid, this.visibleColumns, this._gridOptions);
281+
}
269282
/**
270283
* Translate the Grid Menu ColumnTitle and CustomTitle.
271284
* Note that the only way that seems to work is to destroy and re-create the Grid Menu

0 commit comments

Comments
 (0)