@@ -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