Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): allow to export only displayed, filtered data (#2059)
Browse files Browse the repository at this point in the history
closes #1361

Co-authored-by: Sebastian Leidig <sebastian@aam-digital.com>
brajesh-lab and sleidig committed Nov 7, 2023
1 parent 4a6900d commit 2e28d3d
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -94,7 +94,6 @@ export interface TableRow<T extends Entity> {
})
export class EntitySubrecordComponent<T extends Entity> implements OnChanges {
@Input() isLoading: boolean;

@Input() clickMode: "popup" | "navigate" | "none" = "popup";

@Input() showInactive = false;
@@ -115,6 +114,9 @@ export class EntitySubrecordComponent<T extends Entity> implements OnChanges {
/** data to be displayed, can also be used as two-way-binding */
@Input() records: T[] = [];

/** output the currently displayed records, whenever filters for the user change */
@Output() filteredRecordsChange = new EventEmitter<T[]>();

/**
* factory method to create a new instance of the displayed Entity type
* used when the user adds a new entity to the list.
@@ -266,6 +268,9 @@ export class EntitySubrecordComponent<T extends Entity> implements OnChanges {
this.sortDefault();
}

this.filteredRecordsChange.emit(
this.recordsDataSource.filteredData.map((item) => item.record),
);
this.listenToEntityUpdates();
}

21 changes: 20 additions & 1 deletion src/app/core/entity-list/entity-list/entity-list.component.html
Original file line number Diff line number Diff line change
@@ -129,6 +129,7 @@ <h2>{{ listName }}</h2>
[filter]="filterObj"
[defaultSort]="listConfig?.defaultSort"
[showInactive]="showInactive"
(filteredRecordsChange)="filteredData = $event"
></app-entity-subrecord>
</ng-template>

@@ -183,7 +184,25 @@ <h2>{{ listName }}</h2>
aria-label="download csv"
icon="download"
></fa-icon>
<span i18n="Download list contents as CSV"> Download CSV </span>
<span i18n="Download list contents as CSV"> Download all data (.csv) </span>
</button>

<button
mat-menu-item
[appExportData]="filteredData"
format="csv"
[exportConfig]="listConfig?.exportConfig"
[filename]="listName.replace(' ', '')"
angulartics2On="click"
[angularticsCategory]="entityConstructor?.ENTITY_TYPE"
angularticsAction="list_csv_export"
>
<fa-icon
class="color-accent standard-icon-with-text"
aria-label="download csv"
icon="download"
></fa-icon>
<span i18n="Download list contents as CSV"> Download current (.csv) </span>
</button>

<button
Original file line number Diff line number Diff line change
@@ -114,6 +114,7 @@ export class EntityListComponent<T extends Entity>

filterObj: DataFilter<T>;
filterString = "";
filteredData = [];

get selectedColumnGroupIndex(): number {
return this.selectedColumnGroupIndex_;
@@ -260,10 +261,13 @@ export class EntityListComponent<T extends Entity>
}

applyFilter(filterValue: string) {
// TODO: turn this into one of our filter types, so that all filtering happens the same way (and we avoid accessing internal datasource of sub-component here)
filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.entityTable.recordsDataSource.filter = filterValue;

this.filteredData = this.entityTable.recordsDataSource.filteredData.map(
(x) => x.record,
);
this.analyticsService.eventTrack("list_filter_freetext", {
category: this.entityConstructor?.ENTITY_TYPE,
});

0 comments on commit 2e28d3d

Please sign in to comment.