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

Commit 8257e69

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
refactor(example): add Row Detail dynamic method call demo
1 parent 8c1f835 commit 8257e69

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

src/app/examples/grid-rowdetail.component.html

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
<div class="container-fluid">
2-
<h2>{{title}}</h2>
3-
<div class="subtitle" [innerHTML]="subTitle"></div>
2+
<h2>{{title}}</h2>
3+
<div class="subtitle" [innerHTML]="subTitle"></div>
44

5-
<span>
6-
<label for="">Detail View Rows Shown: </label>
7-
<input type="number" [(ngModel)]="detailViewRowCount">
8-
<button class="btn btn-outline-secondary btn-xs" (click)="changeDetailViewRowCount()">
9-
Set
10-
</button>
11-
</span>
5+
<span>
6+
<button class="btn btn-default btn-sm" (click)="closeAllRowDetail()">
7+
Close All Row Details
8+
</button>
9+
&nbsp;&nbsp;
10+
<label for="">Detail View Rows Shown: </label>
11+
<input type="number" [(ngModel)]="detailViewRowCount">
12+
<button class="btn btn-default btn-xs" (click)="changeDetailViewRowCount()">
13+
Set
14+
</button>
15+
</span>
1216

13-
<hr/>
17+
<hr />
1418

15-
<angular-slickgrid gridId="grid21"
16-
[columnDefinitions]="columnDefinitions"
17-
[gridOptions]="gridOptions"
18-
[dataset]="dataset"
19-
(onAngularGridCreated)="angularGridReady($event)">
20-
</angular-slickgrid>
19+
<angular-slickgrid gridId="grid21"
20+
[columnDefinitions]="columnDefinitions"
21+
[gridOptions]="gridOptions"
22+
[dataset]="dataset"
23+
(onAngularGridCreated)="angularGridReady($event)">
24+
</angular-slickgrid>
2125
</div>
22-

src/app/examples/grid-rowdetail.component.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const NB_ITEMS = 500;
2020
export class GridRowDetailComponent implements OnInit {
2121
title = 'Example 21: Row Detail View';
2222
subTitle = `
23-
Add functionality to show extra information with a Row Detail View
23+
Add functionality to show extra information with a Row Detail View, (<a href="https://github.com/ghiscoding/Angular-Slickgrid/wiki/Row-Detail" target="_blank">Wiki docs</a>)
2424
<ul>
2525
<li>Click on the row "+" icon or anywhere on the row to open it (the latter can be changed via property "useRowClick: false")</li>
2626
<li>Pass a View/Model as a Template to the Row Detail</li>
@@ -43,6 +43,10 @@ export class GridRowDetailComponent implements OnInit {
4343
this.angularGrid = angularGrid;
4444
}
4545

46+
get rowDetailInstance(): any {
47+
return this.angularGrid && this.angularGrid.extensionService.getSlickgridAddonInstance(ExtensionName.rowDetailView) || {};
48+
}
49+
4650
ngOnInit(): void {
4751
this.defineGrid();
4852
}
@@ -86,7 +90,7 @@ export class GridRowDetailComponent implements OnInit {
8690
rowDetailView: {
8791
// We can load the "process" asynchronously in 2 different ways (httpClient OR even Promise)
8892
process: (item) => this.simulateServerAsyncCall(item),
89-
// process: this.httpFetch.fetch(`api/item/${item.id}`),
93+
// process: (item) => this.http.get(`api/item/${item.id}`),
9094

9195
// load only once and reuse the same item detail without calling process method
9296
loadOnce: true,
@@ -108,10 +112,10 @@ export class GridRowDetailComponent implements OnInit {
108112
// for example, display the expand icon only on every 2nd row
109113
// expandableOverride: (row: number, dataContext: any, grid: any) => (dataContext.id % 2 === 1),
110114

111-
// Preload View Template
115+
// Preload View Component
112116
preloadComponent: RowDetailPreloadComponent,
113117

114-
// ViewModel Template to load when row detail data is ready
118+
// View Component to load when row detail data is ready
115119
viewComponent: RowDetailViewComponent,
116120
}
117121
};
@@ -144,10 +148,17 @@ export class GridRowDetailComponent implements OnInit {
144148

145149
changeDetailViewRowCount() {
146150
if (this.angularGrid && this.angularGrid.extensionService) {
147-
const rowDetailInstance = this.angularGrid.extensionService.getSlickgridAddonInstance(ExtensionName.rowDetailView);
148-
const options = rowDetailInstance.getOptions();
149-
options.panelRows = this.detailViewRowCount; // change number of rows dynamically
150-
rowDetailInstance.setOptions(options);
151+
const options = this.rowDetailInstance.getOptions();
152+
if (options && options.panelRows) {
153+
options.panelRows = this.detailViewRowCount; // change number of rows dynamically
154+
this.rowDetailInstance.setOptions(options);
155+
}
156+
}
157+
}
158+
159+
closeAllRowDetail() {
160+
if (this.angularGrid && this.angularGrid.extensionService) {
161+
this.rowDetailInstance.collapseAll();
151162
}
152163
}
153164

0 commit comments

Comments
 (0)