Skip to content

Commit

Permalink
fix(GridState): calling getAssociatedGridColumns should extend column…
Browse files Browse the repository at this point in the history
… (part2) (#1015)

* fix(GridState): calling `getAssociatedGridColumns` should extend column
- extends the previous PR #1014, but instead of merging all column properties, we will actually skip the `width` property since that property is changed internally by SlickGrid (auto-calculated) and that has an impact when using autoResizeColumnsByCellContent feature (for example it breaks our Salesforce grid that uses `enabledAutoResizeColumnsByCellContent` and uses much thinner column width, if we however skip the width then we make SlickGrid recalculate the width since we use `enabledAutoResizeColumnsByCellContent` and that fixes our problem)
  • Loading branch information
ghiscoding committed Jun 29, 2023
1 parent 77cec0c commit 3ea1d02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Expand Up @@ -413,13 +413,13 @@ describe('GridStateService', () => {
// cssClass: red will change to purple and headerCssClass will remain blue when defined in either
expect(associatedGridColumns).toEqual([
{ id: 'field1', field: 'field1', width: 100, cssClass: 'purple', headerCssClass: 'custom-hdr' },
{ id: 'field2', field: 'field2', width: 150, cssClass: '', headerCssClass: 'blue' },
{ id: 'field3', field: 'field3', width: 0, cssClass: '', headerCssClass: '' },
{ id: 'field2', field: 'field2', width: 150, cssClass: undefined, headerCssClass: 'blue' },
{ id: 'field3', field: 'field3', width: 0, cssClass: undefined, headerCssClass: undefined },
]);
expect(columns).toEqual([
{ id: 'field1', field: 'field1', width: 100, cssClass: 'purple', headerCssClass: 'custom-hdr' },
{ id: 'field2', field: 'field2', width: 150, cssClass: '', headerCssClass: 'blue' },
{ id: 'field3', field: 'field3', width: 0, cssClass: '', headerCssClass: '' },
{ id: 'field2', field: 'field2', width: 150, cssClass: undefined, headerCssClass: 'blue' },
{ id: 'field3', field: 'field3', width: 0, cssClass: undefined, headerCssClass: undefined },
]);
});
});
Expand Down
9 changes: 7 additions & 2 deletions packages/common/src/services/gridState.service.ts
Expand Up @@ -21,7 +21,6 @@ import type { FilterService } from './filter.service';
import type { SharedService } from './shared.service';
import type { SortService } from './sort.service';
import type { TreeDataService } from './treeData.service';
import { objectWithoutKey } from './utilities';

// using external non-typed js libraries
declare const Slick: SlickNamespace;
Expand Down Expand Up @@ -221,7 +220,13 @@ export class GridStateService {
if (gridColumn?.id) {
columns.push({
...gridColumn,
...objectWithoutKey(currentColumn, 'columnId') // extend all currentCol proops except "columnId" which isn't needed
cssClass: currentColumn.cssClass || gridColumn.cssClass,
headerCssClass: currentColumn.headerCssClass || gridColumn.headerCssClass,

// for the width we will only pull the custom width or else nothing
// since we don't want to use the default width that SlickGrid uses internally (which is 60px),
// because that would cancel any column resize done by Slickgrid-Universal (like autoResizeColumnsByCellContent)
width: currentColumn.width
});
}
});
Expand Down
Binary file not shown.

0 comments on commit 3ea1d02

Please sign in to comment.