Skip to content

Commit 03c2c64

Browse files
committed
feat: (re)add option to cancel Row Detail opening
- I tried to implement this feature in a previous PR but that introduced a regression which is got fixed in this PR and reintroduces this feature without regressing this time.
1 parent 9b923a8 commit 03c2c64

File tree

4 files changed

+39
-29
lines changed

4 files changed

+39
-29
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h2>
1515
<button class="btn btn-outline-secondary btn-xs" (click)="changeEditableGrid()" data-test="editable-grid-btn">
1616
Make Grid Editable
1717
</button>
18-
<button class="btn btn-outline-secondary btn-xs" (click)="closeAllRowDetail()" data-test="close-all-btn">
18+
<button class="btn btn-outline-secondary btn-xs" (click)="closeAllRowDetail()" data-test="collapse-all-btn">
1919
Close All Row Details
2020
</button>
2121
&nbsp;&nbsp;

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,17 @@ export class GridRowDetailComponent implements OnInit {
123123
viewComponent: RowDetailViewComponent,
124124

125125
// Optionally pass your Parent Component reference to your Child Component (row detail component)
126-
parent: this
126+
parent: this,
127+
128+
onBeforeRowDetailToggle: (e, args) => {
129+
// you coud cancel opening certain rows
130+
// if (args.item.rowId === 1) {
131+
// e.preventDefault();
132+
// return false;
133+
// }
134+
console.log('before toggling row detail', args.item);
135+
return true;
136+
},
127137
}
128138
};
129139

@@ -165,6 +175,7 @@ export class GridRowDetailComponent implements OnInit {
165175
}
166176

167177
changeEditableGrid() {
178+
this.rowDetailInstance.collapseAll();
168179
this.rowDetailInstance.addonOptions.useRowClick = false;
169180
this.gridOptions.autoCommitEdit = !this.gridOptions.autoCommitEdit;
170181
this.angularGrid?.slickGrid.setOptions({

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
164164
this.handleOnBeforeRowDetailToggle(e, args);
165165

166166
if (this.rowDetailViewOptions && typeof this.rowDetailViewOptions.onBeforeRowDetailToggle === 'function') {
167-
this.rowDetailViewOptions.onBeforeRowDetailToggle(e, args);
167+
return this.rowDetailViewOptions.onBeforeRowDetailToggle(e, args);
168168
}
169+
return true;
169170
});
170171
}
171172

@@ -329,7 +330,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
329330
*/
330331
protected handleOnBeforeRowDetailToggle(e: Event, args: { grid: SlickGrid; item: any; }) {
331332
// expanding
332-
if (args && args.item && args.item.__collapsed) {
333+
if (args?.item?.__collapsed) {
333334
// expanding row detail
334335
const viewInfo: CreatedView = {
335336
id: args.item[this.datasetIdPropName],

test/cypress/e2e/example21.cy.ts

+23-25
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe('Example 21 - Row Detail View', () => {
137137
.find('h3')
138138
.contains('Task 0');
139139

140-
cy.get('[data-test=close-all-btn]')
140+
cy.get('[data-test=collapse-all-btn]')
141141
.click();
142142

143143
cy.get('.slick-viewport-top.slick-viewport-left')
@@ -164,7 +164,7 @@ describe('Example 21 - Row Detail View', () => {
164164
});
165165

166166
it('should open a few Row Details, then sort by Title and expect all Row Details to be closed afterward', () => {
167-
const expectedTasks = ['Task 1', 'Task 10', 'Task 100', 'Task 101', 'Task 102', 'Task 103', 'Task 104'];
167+
const expectedTasks = ['Task 0', 'Task 1', 'Task 10', 'Task 100', 'Task 101', 'Task 102', 'Task 103', 'Task 104'];
168168

169169
cy.get('#grid21')
170170
.find('.slick-row:nth(0)')
@@ -247,24 +247,28 @@ describe('Example 21 - Row Detail View', () => {
247247
});
248248
});
249249

250-
it('should click open Row Detail of Task 102 then type a title filter of "Task 102" and expect Row Detail to be opened and still be rendered', () => {
250+
it('should click open Row Detail of Task 1 and Task 101 then type a title filter of "Task 101" and expect Row Detail to be opened and still be rendered', () => {
251251
cy.get('#grid21')
252252
.find('.slick-row:nth(4)')
253253
.click();
254254

255255
cy.get('#grid21')
256-
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_102 .container_102')
256+
.find('.slick-row:nth(1)')
257+
.click();
258+
259+
cy.get('#grid21')
260+
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_101')
257261
.as('detailContainer');
258262

259263
cy.get('@detailContainer')
260264
.find('h3')
261-
.contains('Task 102');
265+
.contains('Task 101');
262266

263267
cy.get('.search-filter.filter-title')
264-
.type('Task 102');
268+
.type('Task 101');
265269
});
266270

267-
it('should call "Clear all Filters" from Grid Menu and expect "Task 102" to still be rendered correctly', () => {
271+
it('should call "Clear all Filters" from Grid Menu and expect "Task 101" to still be rendered correctly', () => {
268272
cy.get('#grid21')
269273
.find('button.slick-grid-menu-button')
270274
.trigger('click')
@@ -278,15 +282,15 @@ describe('Example 21 - Row Detail View', () => {
278282
.click();
279283

280284
cy.get('#grid21')
281-
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_102 .container_102')
285+
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_101')
282286
.as('detailContainer');
283287

284288
cy.get('@detailContainer')
285289
.find('h3')
286-
.contains('Task 102');
290+
.contains('Task 101');
287291
});
288292

289-
it('should call "Clear all Sorting" from Grid Menu and expect "Task 102" to still be rendered correctly', () => {
293+
it('should call "Clear all Sorting" from Grid Menu and expect all row details to be collapsed', () => {
290294
cy.get('#grid21')
291295
.find('button.slick-grid-menu-button')
292296
.trigger('click')
@@ -302,45 +306,39 @@ describe('Example 21 - Row Detail View', () => {
302306
.find('.slick-sort-indicator-asc')
303307
.should('have.length', 0);
304308

305-
cy.get('#grid21')
306-
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_102 .container_102')
307-
.as('detailContainer');
308-
309-
cy.get('@detailContainer')
310-
.find('h3')
311-
.contains('Task 102');
309+
cy.get('.dynamic-cell-detail').should('have.length', 0);
312310
});
313311

314312
it('should close all row details & make grid editable', () => {
315-
cy.get('[data-test="close-all-btn"]').click();
313+
cy.get('[data-test="collapse-all-btn"]').click();
316314
cy.get('[data-test="editable-grid-btn"]').click();
317315
});
318316

319-
it('should click on 3rd row detail open icon and expect it to open', () => {
317+
it('should click on 5th row detail open icon and expect it to open', () => {
320318
cy.get('#grid21')
321-
.find('.slick-row:nth(2) .slick-cell:nth(0)')
319+
.find('.slick-row:nth(4) .slick-cell:nth(0)')
322320
.click();
323321

324322
cy.get('#grid21')
325-
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_100 .container_100')
323+
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_101')
326324
.as('detailContainer');
327325

328326
cy.get('@detailContainer')
329327
.find('h3')
330-
.contains('Task 100');
328+
.contains('Task 101');
331329
});
332330

333-
it('should click on 1st row "Title" cell to edit it and expect row detail to get closed', () => {
331+
it('should click on 2nd row "Title" cell to edit it and expect Task 5 row detail to get closed', () => {
334332
cy.get('#grid21')
335333
.find('.slick-row:nth(1) .slick-cell:nth(1)')
336334
.click();
337335

338336
cy.get('.editor-title')
339337
.invoke('val')
340-
.then(text => expect(text).to.eq('Task 10'));
338+
.then(text => expect(text).to.eq('Task 1'));
341339

342340
cy.get('#grid21')
343-
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_100 .container_100')
341+
.find('.slick-cell + .dynamic-cell-detail .innerDetailView_101')
344342
.should('not.exist');
345343
});
346344
});

0 commit comments

Comments
 (0)