Skip to content

Commit 09cc298

Browse files
committed
fix(plugin): Row Detail column sorting was offset, fixes #949
- fixes #949 - Row Detail extension columns were offset by 1 column (ie, clicking on 2nd column would sort 1st column), internally the RowDetail extension has to be instantiated a little bit more early within Angular-Slickgrid for it to properly sync columns and so on - added couple more Cypress E2E tests to cover the Sorting icons to be displayed under the expected column
1 parent 7be3443 commit 09cc298

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

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

+6-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
22
import {
33
AngularGridInstance,
44
Column,
5-
ExtensionList,
65
FieldType,
76
Filters,
87
Formatters,
@@ -12,7 +11,7 @@ import {
1211
import { RowDetailViewComponent } from './rowdetail-view.component';
1312
import { RowDetailPreloadComponent } from './rowdetail-preload.component';
1413

15-
const NB_ITEMS = 500;
14+
const NB_ITEMS = 1000;
1615

1716
@Component({
1817
templateUrl: './grid-rowdetail.component.html'
@@ -29,12 +28,12 @@ export class GridRowDetailComponent implements OnInit {
2928
`;
3029

3130
angularGrid!: AngularGridInstance;
32-
columnDefinitions!: Column[];
31+
columnDefinitions: Column[] = [];
3332
gridOptions!: GridOption;
34-
dataset!: any[];
33+
dataset: any[] = [];
3534
detailViewRowCount = 9;
36-
message = '';
3735
flashAlertType = 'info';
36+
message = '';
3837

3938
constructor() { }
4039

@@ -58,12 +57,6 @@ export class GridRowDetailComponent implements OnInit {
5857

5958
/* Define grid Options and Columns */
6059
defineGrid() {
61-
// prepare a multiple-select array to filter with
62-
const multiSelectFilterArray = [];
63-
for (let i = 0; i < NB_ITEMS; i++) {
64-
multiSelectFilterArray.push({ value: i, label: i });
65-
}
66-
6760
this.columnDefinitions = [
6861
{ id: 'title', name: 'Title', field: 'title', sortable: true, type: FieldType.string, width: 70, filterable: true },
6962
{ id: 'duration', name: 'Duration (days)', field: 'duration', formatter: Formatters.decimal, params: { minDecimal: 1, maxDecimal: 2 }, sortable: true, type: FieldType.number, minWidth: 90, filterable: true },
@@ -138,7 +131,7 @@ export class GridRowDetailComponent implements OnInit {
138131
getData() {
139132
// mock a dataset
140133
this.dataset = [];
141-
for (let i = 0; i < 1000; i++) {
134+
for (let i = 0; i < NB_ITEMS; i++) {
142135
const randomYear = 2000 + Math.floor(Math.random() * 10);
143136
const randomMonth = Math.floor(Math.random() * 11);
144137
const randomDay = Math.floor((Math.random() * 29));
@@ -202,4 +195,4 @@ export class GridRowDetailComponent implements OnInit {
202195
private randomNumber(min: number, max: number) {
203196
return Math.floor(Math.random() * (max - min + 1) + min);
204197
}
205-
}
198+
}

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
900900
// filtering data with local dataset will not always show correctly unless we call this updateRow/render
901901
// also don't use "invalidateRows" since it destroys the entire row and as bad user experience when updating a row
902902
// see commit: https://github.com/ghiscoding/aurelia-slickgrid/commit/8c503a4d45fba11cbd8d8cc467fae8d177cc4f60
903-
if (gridOptions && gridOptions.enableFiltering && !gridOptions.enableRowDetailView) {
903+
if (gridOptions?.enableFiltering && !gridOptions.enableRowDetailView) {
904904
if (args?.rows && Array.isArray(args.rows)) {
905905
args.rows.forEach((row: number) => grid.updateRow(row));
906906
grid.render();
@@ -1215,12 +1215,19 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
12151215
return options;
12161216
}
12171217

1218-
/** Pre-Register any Resource that don't require SlickGrid to be instantiated (for example RxJS Resource) */
1218+
/** Pre-Register any Resource that don't require SlickGrid to be instantiated (for example RxJS Resource & RowDetail) */
12191219
private preRegisterResources() {
12201220
this._registeredResources = this.gridOptions.registerExternalResources || [];
12211221

12221222
// Angular-Slickgrid requires RxJS, so we'll register it as the first resource
12231223
this.registerRxJsResource(new RxJsResource() as RxJsFacade);
1224+
1225+
if (this.gridOptions.enableRowDetailView) {
1226+
this.slickRowDetailView = new SlickRowDetailView(this.angularUtilService, this.appRef, this._eventPubSubService, this.elm.nativeElement, this.rxjs);
1227+
this.slickRowDetailView.create(this.columnDefinitions, this.gridOptions);
1228+
this._registeredResources.push(this.slickRowDetailView);
1229+
this.extensionService.addExtensionToList(ExtensionName.rowDetailView, { name: ExtensionName.rowDetailView, instance: this.slickRowDetailView });
1230+
}
12241231
}
12251232

12261233
private registerResources() {
@@ -1247,13 +1254,6 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
12471254
this.extensionService.translateColumnHeaders();
12481255
}
12491256

1250-
if (this.gridOptions.enableRowDetailView) {
1251-
this.slickRowDetailView = new SlickRowDetailView(this.angularUtilService, this.appRef, this._eventPubSubService, this.elm.nativeElement, this.rxjs);
1252-
this.slickRowDetailView.create(this.columnDefinitions, this.gridOptions);
1253-
this._registeredResources.push(this.slickRowDetailView);
1254-
this.extensionService.addExtensionToList(ExtensionName.rowDetailView, { name: ExtensionName.rowDetailView, instance: this.slickRowDetailView });
1255-
}
1256-
12571257
// also initialize (render) the empty warning component
12581258
this.slickEmptyWarning = new SlickEmptyWarningComponent();
12591259
this._registeredResources.push(this.slickEmptyWarning);

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

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import 'slickgrid/plugins/slick.rowdetailview';
2-
import 'slickgrid/plugins/slick.rowselectionmodel';
3-
41
import { ApplicationRef, ComponentRef, Type, ViewContainerRef } from '@angular/core';
52
import {
63
addToArrayWhenNotExists,

test/cypress/e2e/example21.cy.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('Example 21 - Row Detail View', { retries: 1 }, () => {
166166
});
167167

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

171171
cy.get('#grid21')
172172
.find('.slick-row:nth(0)')
@@ -221,6 +221,11 @@ describe('Example 21 - Row Detail View', { retries: 1 }, () => {
221221
.should('contain', 'Sort Ascending')
222222
.click();
223223

224+
cy.get('#grid21')
225+
.find('.slick-header-column:nth(1)')
226+
.find('.slick-sort-indicator-asc')
227+
.should('have.length', 1);
228+
224229
cy.get('.slick-viewport-top.slick-viewport-left')
225230
.scrollTo('top');
226231

@@ -295,6 +300,10 @@ describe('Example 21 - Row Detail View', { retries: 1 }, () => {
295300
.contains('Clear all Sorting')
296301
.click();
297302

303+
cy.get('#grid21')
304+
.find('.slick-sort-indicator-asc')
305+
.should('have.length', 0);
306+
298307
cy.get('#grid21')
299308
.find('.innerDetailView_102 .container_102')
300309
.as('detailContainer');

0 commit comments

Comments
 (0)