Skip to content

Commit

Permalink
fix(state): don't use previous columns ref when getting current cols
Browse files Browse the repository at this point in the history
- in our current project, if we were to create a Grid View by hidding some columns and then revert to default Grid View and then creating a 2nd Grid View it would reuse the hidden columns from the 1st Grid View even though we wanted to base our 2nd Grid View from the base (which is supposed to have all columns shown)... so basically the issue was that we shouldn't keep/reuse of the columns, we should reevaluate every time
  • Loading branch information
ghiscoding committed Aug 23, 2021
1 parent 01158bb commit f312c60
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/common/src/services/grid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,14 @@ export class GridService {

/** Select the selected row by a row index */
setSelectedRow(rowIndex: number) {
if (this._grid && this._grid.setSelectedRows) {
if (this._grid?.setSelectedRows) {
this._grid.setSelectedRows([rowIndex]);
}
}

/** Set selected rows with provided array of row indexes */
setSelectedRows(rowIndexes: number[]) {
if (this._grid && this._grid.setSelectedRows) {
if (this._grid?.setSelectedRows) {
this._grid.setSelectedRows(rowIndexes);
}
}
Expand All @@ -364,13 +364,13 @@ export class GridService {
*/
resetGrid(columnDefinitions?: Column[]) {
// reset columns to original states & refresh the grid
if (this._grid && this._dataView) {
if (this._grid) {
const originalColumns = this.sharedService.allColumns || [];

if (Array.isArray(originalColumns) && originalColumns.length > 0) {
// set the grid columns to it's original column definitions
this._grid.setColumns(originalColumns);
if (this._gridOptions && this._gridOptions.enableAutoSizeColumns) {
if (this._gridOptions?.enableAutoSizeColumns) {
this._grid.autosizeColumns();
}
this.gridStateService.resetColumns(columnDefinitions);
Expand Down
9 changes: 1 addition & 8 deletions packages/common/src/services/gridState.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ declare const Slick: SlickNamespace;
export class GridStateService {
protected _eventHandler = new Slick.EventHandler();
protected _columns: Column[] = [];
protected _currentColumns: CurrentColumn[] = [];
protected _grid!: SlickGrid;
protected _subscriptions: EventSubscription[] = [];
protected _selectedRowDataContextIds: Array<number | string> | undefined = []; // used with row selection
Expand Down Expand Up @@ -88,7 +87,6 @@ export class GridStateService {

/** Dispose of all the SlickGrid & PubSub subscriptions */
dispose() {
this._currentColumns = [];
this._columns = [];

// unsubscribe all SlickGrid events
Expand Down Expand Up @@ -217,7 +215,6 @@ export class GridStateService {
}
});
}
this._currentColumns = currentColumns;
return currentColumns;
}

Expand Down Expand Up @@ -253,11 +250,7 @@ export class GridStateService {
*/
getCurrentColumns(): CurrentColumn[] {
let currentColumns: CurrentColumn[] = [];
if (this._currentColumns && Array.isArray(this._currentColumns) && this._currentColumns.length > 0) {
currentColumns = this._currentColumns;
} else {
currentColumns = this.getAssociatedCurrentColumns(this._grid.getColumns());
}
currentColumns = this.getAssociatedCurrentColumns(this._grid.getColumns());

return currentColumns;
}
Expand Down
2 changes: 0 additions & 2 deletions packages/common/src/styles/slick-grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
display: inline-block;
box-sizing: content-box !important; /* this here only for Firefox! */
overflow: hidden;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
height: 16px;
line-height: 16px;
Expand Down Expand Up @@ -140,7 +139,6 @@
display: inline-block;
box-sizing: content-box !important;
overflow: hidden;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
height: 16px;
line-height: 16px;
Expand Down
Binary file not shown.

0 comments on commit f312c60

Please sign in to comment.