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

Commit 757155f

Browse files
committed
fix(composite): selected row count always 0 on mass-selected, fix #951
- fixes #951 - add dispose method to container service to start with a blank array whenever we route to another page, this is to avoid reusing already disposed services that might still be in the container service
1 parent 88fd6ee commit 757155f

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
306306
this.groupingService = externalServices?.groupingAndColspanService ?? new GroupingAndColspanService(this.extensionUtility, this._eventPubSubService);
307307

308308
this.serviceList = [
309+
this.containerService,
309310
this.extensionService,
310311
this.filterService,
311312
this.gridEventService,
@@ -423,6 +424,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
423424
this.datasetHierarchical = undefined;
424425
this._columnDefinitions = [];
425426
this._angularGridInstances = undefined;
427+
this.slickGrid = undefined as any;
426428
}
427429

428430
emptyGridContainerElm() {
@@ -556,8 +558,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
556558

557559
// if you don't want the items that are not visible (due to being filtered out or being on a different page)
558560
// to stay selected, pass 'false' to the second arg
559-
const selectionModel = this.slickGrid?.getSelectionModel();
560-
if (selectionModel && this.gridOptions && this.gridOptions.dataView && this.gridOptions.dataView.hasOwnProperty('syncGridSelection')) {
561+
if (this.slickGrid?.getSelectionModel() && this.gridOptions && this.gridOptions.dataView && this.gridOptions.dataView.hasOwnProperty('syncGridSelection')) {
561562
// if we are using a Backend Service, we will do an extra flag check, the reason is because it might have some unintended behaviors
562563
// with the BackendServiceApi because technically the data in the page changes the DataView on every page change.
563564
let preservedRowSelectionWithBackend = false;
@@ -884,29 +885,28 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
884885
// When data changes in the DataView, we need to refresh the metrics and/or display a warning if the dataset is empty
885886
this._eventHandler.subscribe(dataView.onRowCountChanged, () => {
886887
grid.invalidate();
887-
this.handleOnItemCountChanged(this.dataView.getFilteredItemCount() || 0, dataView.getItemCount());
888+
this.handleOnItemCountChanged(dataView.getFilteredItemCount() || 0, dataView.getItemCount() || 0);
888889
});
889890
this._eventHandler.subscribe(dataView.onSetItemsCalled, (_e, args) => {
890-
grid.invalidate();
891-
this.handleOnItemCountChanged(this.dataView.getFilteredItemCount(), args.itemCount);
891+
this.handleOnItemCountChanged(dataView.getFilteredItemCount() || 0, args.itemCount);
892892

893893
// when user has resize by content enabled, we'll force a full width calculation since we change our entire dataset
894894
if (args.itemCount > 0 && (this.gridOptions.autosizeColumnsByCellContentOnFirstLoad || this.gridOptions.enableAutoResizeColumnsByCellContent)) {
895895
this.resizerService.resizeColumnsByCellContent(!this.gridOptions?.resizeByContentOnlyOnFirstLoad);
896896
}
897897
});
898898

899-
this._eventHandler.subscribe(dataView.onRowsChanged, (_e, args) => {
900-
// filtering data with local dataset will not always show correctly unless we call this updateRow/render
901-
// also don't use "invalidateRows" since it destroys the entire row and as bad user experience when updating a row
902-
// see commit: https://github.com/ghiscoding/aurelia-slickgrid/commit/8c503a4d45fba11cbd8d8cc467fae8d177cc4f60
903-
if (gridOptions?.enableFiltering && !gridOptions.enableRowDetailView) {
899+
if (gridOptions?.enableFiltering && !gridOptions.enableRowDetailView) {
900+
this._eventHandler.subscribe(dataView.onRowsChanged, (_e, args) => {
901+
// filtering data with local dataset will not always show correctly unless we call this updateRow/render
902+
// also don't use "invalidateRows" since it destroys the entire row and as bad user experience when updating a row
903+
// see commit: https://github.com/ghiscoding/aurelia-slickgrid/commit/8c503a4d45fba11cbd8d8cc467fae8d177cc4f60
904904
if (args?.rows && Array.isArray(args.rows)) {
905905
args.rows.forEach((row: number) => grid.updateRow(row));
906906
grid.render();
907907
}
908-
}
909-
});
908+
});
909+
}
910910
}
911911
}
912912

@@ -1150,9 +1150,8 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
11501150
private loadRowSelectionPresetWhenExists() {
11511151
// if user entered some Row Selections "presets"
11521152
const presets = this.gridOptions?.presets;
1153-
const selectionModel = this.slickGrid?.getSelectionModel();
11541153
const enableRowSelection = this.gridOptions && (this.gridOptions.enableCheckboxSelector || this.gridOptions.enableRowSelection);
1155-
if (enableRowSelection && selectionModel && presets && presets.rowSelection && (Array.isArray(presets.rowSelection.gridRowIndexes) || Array.isArray(presets.rowSelection.dataContextIds))) {
1154+
if (enableRowSelection && this.slickGrid?.getSelectionModel() && presets?.rowSelection && (Array.isArray(presets.rowSelection.gridRowIndexes) || Array.isArray(presets.rowSelection.dataContextIds))) {
11561155
let dataContextIds = presets.rowSelection.dataContextIds;
11571156
let gridRowIndexes = presets.rowSelection.gridRowIndexes;
11581157

@@ -1262,7 +1261,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
12621261
// register all services by executing their init method and providing them with the Grid object
12631262
if (Array.isArray(this._registeredResources)) {
12641263
for (const resource of this._registeredResources) {
1265-
if (typeof resource.init === 'function') {
1264+
if (this.slickGrid && typeof resource.init === 'function') {
12661265
resource.init(this.slickGrid, this.containerService);
12671266
}
12681267
}

src/app/modules/angular-slickgrid/services/container.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export class ContainerService implements UniversalContainerService {
1515
return null;
1616
}
1717

18+
dispose() {
19+
this.dependencies = [];
20+
}
21+
1822
registerInstance(key: string, instance: any) {
1923
const dependency = this.dependencies.some(dep => dep.key === key);
2024
if (!dependency) {

0 commit comments

Comments
 (0)