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

Commit dd4beab

Browse files
committed
fix: Row Detail redraw all should work as expected
1 parent 0e1321e commit dd4beab

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

src/app/examples/grid45-detail.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
1+
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
22
import { AngularGridInstance, Column, GridOption, GridState } from '../modules/angular-slickgrid';
33

44
export interface Distributor {
@@ -25,7 +25,7 @@ export interface OrderData {
2525
templateUrl: './grid45-detail.component.html',
2626
encapsulation: ViewEncapsulation.None,
2727
})
28-
export class Grid45DetailComponent implements OnInit {
28+
export class Grid45DetailComponent implements OnDestroy, OnInit {
2929
model!: Distributor;
3030
innerColDefs: Column[] = [];
3131
innerGridOptions!: GridOption;
@@ -46,6 +46,10 @@ export class Grid45DetailComponent implements OnInit {
4646
this.showGrid = true;
4747
}
4848

49+
ngOnDestroy(): void {
50+
console.log('destroying row detail');
51+
}
52+
4953
angularGridReady(angularGrid: AngularGridInstance) {
5054
this.angularGrid = angularGrid;
5155
}

src/app/examples/grid45.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h2>
2424
</button>
2525
</h2>
2626

27-
<div class="subtitle">
27+
<div class="subtitle" [hidden]="!showSubTitle">
2828
Add functionality to show extra information with a Row Detail View, (<a
2929
href="https://ghiscoding.gitbook.io/angular-slickgrid/grid-functionalities/row-detail"
3030
target="_blank"
@@ -40,7 +40,9 @@ <h2>
4040
<button class="btn btn-outline-secondary btn-sm btn-icon ms-1" data-test="collapse-all-btn" (click)="closeAllRowDetail()">
4141
Close all Row Details
4242
</button>
43-
&nbsp;&nbsp;
43+
<button class="btn btn-outline-secondary btn-sm btn-icon mx-1" data-test="redraw-all-btn" (click)="redrawAllRowDetail()">
44+
Force redraw all Row Details
45+
</button>
4446

4547
<span class="d-inline-flex gap-4px">
4648
<label for="detailViewRowCount">Detail View Rows Shown: </label>

src/app/examples/grid45.component.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ export class Grid45Component implements OnDestroy, OnInit {
160160
}
161161

162162
closeAllRowDetail() {
163-
if (this.angularGrid?.extensionService) {
164-
this.rowDetailInstance.collapseAll();
165-
}
163+
this.rowDetailInstance?.collapseAll();
164+
}
165+
166+
redrawAllRowDetail() {
167+
this.rowDetailInstance?.redrawAllViewComponents(true);
166168
}
167169

168170
/** Just for demo purposes, we will simulate an async server call and return more details on the selected row item */
@@ -230,5 +232,6 @@ export class Grid45Component implements OnDestroy, OnInit {
230232
this.showSubTitle = !this.showSubTitle;
231233
const action = this.showSubTitle ? 'remove' : 'add';
232234
document.querySelector('.subtitle')?.classList[action]('hidden');
235+
this.angularGrid.resizerService?.resizeGrid(1);
233236
}
234237
}

src/app/modules/angular-slickgrid/extensions/slickRowDetailView.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
209209
// hook some events needed by the Plugin itself
210210

211211
// we need to redraw the open detail views if we change column position (column reorder)
212-
this.eventHandler.subscribe(this._grid.onColumnsReordered, this.redrawAllViewComponents.bind(this));
212+
this.eventHandler.subscribe(this._grid.onColumnsReordered, () => this.redrawAllViewComponents());
213213

214214
// on row selection changed, we also need to redraw
215215
if (this.gridOptions.enableRowSelection || this.gridOptions.enableCheckboxSelector) {
216-
this.eventHandler.subscribe(this._grid.onSelectedRowsChanged, this.redrawAllViewComponents.bind(this));
216+
this.eventHandler.subscribe(this._grid.onSelectedRowsChanged, () => this.redrawAllViewComponents());
217217
}
218218

219219
// on sort, all row detail are collapsed so we can dispose of all the Views as well
@@ -223,7 +223,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
223223
this._subscriptions.push(
224224
this.eventPubSubService?.subscribe(
225225
['onFilterChanged', 'onGridMenuColumnsChanged', 'onColumnPickerColumnsChanged'],
226-
this.redrawAllViewComponents.bind(this)
226+
() => this.redrawAllViewComponents()
227227
),
228228
this.eventPubSubService?.subscribe(['onGridMenuClearAllFilters', 'onGridMenuClearAllSorting'], () =>
229229
window.setTimeout(() => this.redrawAllViewComponents())
@@ -235,10 +235,11 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
235235
}
236236

237237
/** Redraw (re-render) all the expanded row detail View Components */
238-
redrawAllViewComponents() {
238+
redrawAllViewComponents(forceRedraw = false) {
239239
this.resetRenderedRows();
240240
this._views.forEach((view) => {
241-
if (!view.rendered) {
241+
if (!view.rendered || forceRedraw) {
242+
forceRedraw && view.componentRef?.destroy();
242243
this.redrawViewComponent(view);
243244
}
244245
});
@@ -321,7 +322,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
321322
const compRef = expandedView?.componentRef;
322323
if (compRef) {
323324
this.appRef.detachView(compRef.hostView);
324-
if (compRef?.destroy) {
325+
if (typeof compRef?.destroy === 'function') {
325326
compRef.destroy();
326327
expandedView.rendered = false;
327328
}

test/cypress/e2e/example45.cy.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ describe('Example 45 - Row Detail with inner Grid', () => {
101101
cy.get(`#innergrid-2 [style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(1)`).should('contain', 'München');
102102
});
103103

104+
it('should force redraw of all Row Details and expect same row details to be opened and opened', () => {
105+
cy.get('[data-test="redraw-all-btn"]').click();
106+
cy.wait(10);
107+
108+
// 2nd row detail
109+
cy.get(`#innergrid-1 [style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(0)`).should('contain', '10261');
110+
cy.get(`#innergrid-1 [style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(1)`).should('contain', 'Rio de Janeiro');
111+
cy.get(`#innergrid-1 [style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(0)`).should('contain', '10267');
112+
cy.get(`#innergrid-1 [style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(1)`).should('contain', 'München');
113+
114+
// 3rd row detail
115+
cy.get('#innergrid-2 .search-filter.filter-orderId').should('have.value', '');
116+
cy.get('#innergrid-2 .search-filter.filter-shipCity').should('have.value', '');
117+
cy.get('#innergrid-2 .slick-sort-indicator-asc').should('not.exist');
118+
cy.get(`#innergrid-2 [style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(0)`).should('contain', '10261');
119+
cy.get(`#innergrid-2 [style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(1)`).should('contain', 'Rio de Janeiro');
120+
cy.get(`#innergrid-2 [style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(0)`).should('contain', '10267');
121+
cy.get(`#innergrid-2 [style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(1)`).should('contain', 'München');
122+
});
123+
104124
it('should close all rows', () => {
105125
cy.get('[data-test="collapse-all-btn"]').click();
106126
});

0 commit comments

Comments
 (0)