Skip to content

Commit

Permalink
fix(picker): add missing pre-header title grouping extractor
Browse files Browse the repository at this point in the history
- also fixed columnpicker instantiation is with grid options instead of columnpicker options
  • Loading branch information
ghiscoding committed Jun 16, 2020
1 parent 1c7d49f commit fa3148b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('columnPickerExtension', () => {
expect(instance).toBeTruthy();
expect(instance).toEqual(addonInstance);
expect(onRegisteredSpy).toHaveBeenCalledWith(instance);
expect(mockAddon).toHaveBeenCalledWith(columnsMock, gridStub, gridOptionsMock.columnPicker);
expect(mockAddon).toHaveBeenCalledWith(columnsMock, gridStub, gridOptionsMock);
});

it('should call internal event handler subscribe and expect the "onColumnSpy" option to be called when addon notify is called', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/extensions/columnPickerExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ColumnPickerExtension implements Extension {
this.sharedService.gridOptions.columnPicker.columnTitle = this.sharedService.gridOptions.columnPicker.columnTitle || columnTitle;
this.sharedService.gridOptions.columnPicker.forceFitTitle = this.sharedService.gridOptions.columnPicker.forceFitTitle || forceFitTitle;
this.sharedService.gridOptions.columnPicker.syncResizeTitle = this.sharedService.gridOptions.columnPicker.syncResizeTitle || syncResizeTitle;
this._addon = new Slick.Controls.ColumnPicker(this.sharedService.allColumns, this.sharedService.grid, this.sharedService.gridOptions.columnPicker);
this._addon = new Slick.Controls.ColumnPicker(this.sharedService.allColumns, this.sharedService.grid, this.sharedService.gridOptions);

if (this.sharedService.grid && this.sharedService.gridOptions.enableColumnPicker) {
if (this._addon && this.sharedService.gridOptions.columnPicker.onExtensionRegistered) {
Expand Down
23 changes: 15 additions & 8 deletions packages/common/src/global-grid-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const GlobalGridOptions: GridOption = {
fadeSpeed: 0,
hideForceFitButton: false,
hideSyncResizeButton: true,
headerColumnValueExtractor: pickerHeaderColumnValueExtractor
},
cellMenu: {
autoAdjustDrop: true,
Expand Down Expand Up @@ -146,14 +147,7 @@ export const GlobalGridOptions: GridOption = {
menuWidth: 16,
resizeOnShowHeaderRow: true,
useClickToRepositionMenu: false, // use icon location to reposition instead
headerColumnValueExtractor: (column: Column) => {
const headerGroup = column?.columnGroup || '';
if (headerGroup) {
// when using Column Header Grouping, we'll prefix the column group title
return headerGroup + ' - ' + column.name;
}
return column?.name ?? '';
}
headerColumnValueExtractor: pickerHeaderColumnValueExtractor
},
headerMenu: {
autoAlign: true,
Expand Down Expand Up @@ -196,3 +190,16 @@ export const GlobalGridOptions: GridOption = {
topPanelHeight: 30,
translationNamespaceSeparator: ':',
};

/**
* Value Extractor for both ColumnPicker & GridMenu Picker
* when using Column Header Grouping, we'll prefix the column group title
* else we'll simply return the column name title
*/
function pickerHeaderColumnValueExtractor(column: Column) {
const headerGroup = column?.columnGroup || '';
if (headerGroup) {
return headerGroup + ' - ' + column.name;
}
return column?.name ?? '';
}
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/slickNamespace.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface SlickNamespace {
// all of the controls are under the Controls namespace
Controls: {
/** A control to add a Column Picker (right+click on any column header to reveal the column picker) */
ColumnPicker: new (columns: Column[], grid: SlickGrid, options?: ColumnPickerOption) => SlickColumnPicker;
ColumnPicker: new (columns: Column[], grid: SlickGrid, options?: GridOption) => SlickColumnPicker;

/** A control to add a Grid Menu (hambuger menu on top-right of the grid) */
GridMenu: new (columns: Column[], grid: SlickGrid, options?: GridOption) => SlickGridMenu;
Expand Down

0 comments on commit fa3148b

Please sign in to comment.