Skip to content

Commit

Permalink
fix(composite): selected row count always 0 on mass-selected, fix #951
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ghiscoding committed Jul 6, 2022
1 parent 88fd6ee commit 757155f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
this.groupingService = externalServices?.groupingAndColspanService ?? new GroupingAndColspanService(this.extensionUtility, this._eventPubSubService);

this.serviceList = [
this.containerService,
this.extensionService,
this.filterService,
this.gridEventService,
Expand Down Expand Up @@ -423,6 +424,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
this.datasetHierarchical = undefined;
this._columnDefinitions = [];
this._angularGridInstances = undefined;
this.slickGrid = undefined as any;
}

emptyGridContainerElm() {
Expand Down Expand Up @@ -556,8 +558,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {

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

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

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

Expand Down Expand Up @@ -1150,9 +1150,8 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
private loadRowSelectionPresetWhenExists() {
// if user entered some Row Selections "presets"
const presets = this.gridOptions?.presets;
const selectionModel = this.slickGrid?.getSelectionModel();
const enableRowSelection = this.gridOptions && (this.gridOptions.enableCheckboxSelector || this.gridOptions.enableRowSelection);
if (enableRowSelection && selectionModel && presets && presets.rowSelection && (Array.isArray(presets.rowSelection.gridRowIndexes) || Array.isArray(presets.rowSelection.dataContextIds))) {
if (enableRowSelection && this.slickGrid?.getSelectionModel() && presets?.rowSelection && (Array.isArray(presets.rowSelection.gridRowIndexes) || Array.isArray(presets.rowSelection.dataContextIds))) {
let dataContextIds = presets.rowSelection.dataContextIds;
let gridRowIndexes = presets.rowSelection.gridRowIndexes;

Expand Down Expand Up @@ -1262,7 +1261,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
// register all services by executing their init method and providing them with the Grid object
if (Array.isArray(this._registeredResources)) {
for (const resource of this._registeredResources) {
if (typeof resource.init === 'function') {
if (this.slickGrid && typeof resource.init === 'function') {
resource.init(this.slickGrid, this.containerService);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class ContainerService implements UniversalContainerService {
return null;
}

dispose() {
this.dependencies = [];
}

registerInstance(key: string, instance: any) {
const dependency = this.dependencies.some(dep => dep.key === key);
if (!dependency) {
Expand Down

0 comments on commit 757155f

Please sign in to comment.