(fetchData)="getOsdList()"
[columns]="columns"
selectionType="single"
- (updateSelection)="updateSelection($event)">
+ (updateSelection)="updateSelection($event)"
+ [updateSelectionOnRefresh]="false">
<cd-osd-details cdTableDetail
[selection]="selection">
</cd-osd-details>
// e.g. 'single' or 'multi'.
@Input() selectionType: string = undefined;
+ // If `true` selected item details will be updated on table refresh
+ @Input() updateSelectionOnRefresh = true;
+
/**
* Should be a function to update the input data if undefined nothing will be triggered
*
}
this.loadingIndicator = false;
this.updating = false;
+ if (this.updateSelectionOnRefresh) {
+ this.updateSelected();
+ }
+ }
+
+ /**
+ * After updating the data, we have to update the selected items
+ * because details may have changed,
+ * or some selected items may have been removed.
+ */
+ updateSelected() {
+ const newSelected = [];
+ this.selection.selected.forEach((selectedItem) => {
+ for (const row of this.data) {
+ if (selectedItem[this.identifier] === row[this.identifier]) {
+ newSelected.push(row);
+ }
+ }
+ });
+ this.selection.selected = newSelected;
+ this.onSelect();
}
onSelect() {