Skip to content

Commit

Permalink
fix(tree): when Tree Data is filtered then Sort, footer count is invalid
Browse files Browse the repository at this point in the history
- use case, if we have filtered data in the grid (any filter is applied and some items are filtered) and we then Sort a column, the item count shown in the Footer was showing the entire dataset count instead of the filtered count. This happens because internally the lib will Sort the hierarchical dataset and then overwrite the DataView flat dataset and when it does that it was changing the footer count.
  • Loading branch information
ghiscoding committed Sep 23, 2021
1 parent 2f975a1 commit 4f5fc44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/common/src/services/__tests__/sort.service.spec.ts
Expand Up @@ -47,11 +47,15 @@ const gridOptionMock = {
} as unknown as GridOption;

const dataViewStub = {
getFilteredItemCount: jest.fn(),
getItemCount: jest.fn(),
getItemMetadata: jest.fn(),
getLength: jest.fn(),
refresh: jest.fn(),
sort: jest.fn(),
reSort: jest.fn(),
sort: jest.fn(),
setItems: jest.fn(),
onRowCountChanged: new Slick.Event(),
} as unknown as SlickDataView;

const backendServiceStub = {
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/services/sort.service.ts
Expand Up @@ -412,6 +412,11 @@ export class SortService {
// we could use the DataView sort but that would require re-sorting again (since the 2nd array that is currently in the DataView would have to be resorted against the 1st array that was sorting from tree sort)
// it is simply much faster to just replace the entire dataset
this._dataView.setItems(datasetSortResult.flat, datasetIdPropertyName);

// also trigger a row count changed to avoid having an invalid filtered item count in the grid footer
// basically without this the item count in the footer is incorrect and shows the full dataset length instead of the previous filtered count
// that happens because we just overwrote the entire dataset the DataView.refresh() doesn't detect a row count change so we trigger it manually
this._dataView.onRowCountChanged.notify({ previous: this._dataView.getFilteredItemCount(), current: this._dataView.getLength(), itemCount: this._dataView.getItemCount(), dataView: this._dataView, callingOnRowsChanged: true });
} else {
dataView.sort(this.sortComparers.bind(this, sortColumns));
}
Expand Down

0 comments on commit 4f5fc44

Please sign in to comment.