Skip to content

Commit

Permalink
Merge pull request #196 from porscheinformatik/bugfix/dataTableDispla…
Browse files Browse the repository at this point in the history
…yedData

fix data table display data
  • Loading branch information
xkilpoi authored Jun 4, 2024
2 parents c9b5290 + a5dea87 commit a96b57d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

<!-- Table -->
<div
*ngIf="filterMode === 'COLUMN_BASED' || showEmptyTable || !!filteredPageData?.length; else noData"
*ngIf="filterMode === 'COLUMN_BASED' || showEmptyTable || !!dataSource.filteredData?.length; else noData"
class="datatable"
[class]="tableClass"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,11 @@ describe('DataTableComponent', () => {
{ rowId: 3, id: 3, name: 'Moose' },
];
component.dataSource = new MatTableDataSource(initialData);
component.dataSource.sort = new MatSort();
component.allSelected = false;
const clearSpy = jest.spyOn(component['_selectionModel'], 'clear');
const selectSpy = jest.spyOn(component['_selectionModel'], 'select');
const getAllDataSourceRowsOfCurrentPageSpy = jest.spyOn(component, 'filteredPageData', 'get');
const getAllDataSourceRowsOfCurrentPageSpy = jest.spyOn(component, 'displayedData', 'get');
component.onToggleSelectAll();

expect(clearSpy).toHaveBeenCalled();
Expand All @@ -522,10 +523,11 @@ describe('DataTableComponent', () => {
{ rowId: 3, name: 'Moose' },
];
component.dataSource = new MatTableDataSource(initialData);
component.dataSource.sort = new MatSort();
component.allSelected = true;
const clearSpy = jest.spyOn(component['_selectionModel'], 'clear');
const selectSpy = jest.spyOn(component['_selectionModel'], 'select');
const getAllDataSourceRowsOfCurrentPageSpy = jest.spyOn(component, 'filteredPageData', 'get');
const getAllDataSourceRowsOfCurrentPageSpy = jest.spyOn(component, 'displayedData', 'get');
component.onToggleSelectAll();

expect(clearSpy).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ export class DataTableComponent implements AfterViewInit, OnChanges {
return !!this._forceSelectionMode ? this._forceSelectionMode : this.actions.find((it) => it.type === 'BATCH') ? 'BATCH' : 'SINGLE';
}

public get filteredPageData(): any[] {
// only use filtered data
return this.dataSource?._pageData(this.dataSource.filteredData);
// get filtered & sorted data of the current page
public get displayedData(): any[] {
return this.dataSource?._pageData(this.dataSource?.sortData(this.dataSource.filteredData, this.dataSource.sort));
}

public get showActionColumn(): boolean {
Expand Down Expand Up @@ -524,7 +524,7 @@ export class DataTableComponent implements AfterViewInit, OnChanges {
this.allSelected = !this.allSelected;
if (this.allSelected) {
// select all rows of the current page
this.filteredPageData.forEach((row) => {
this.displayedData.forEach((row) => {
if (!row.parentId) {
this._selectionModel.select(row.rowId);
}
Expand Down

0 comments on commit a96b57d

Please sign in to comment.