Skip to content

Commit

Permalink
mgr/dashboard: Update selected items on table refresh
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Marques <rimarques@suse.com>
  • Loading branch information
ricardoasmarques committed Apr 9, 2018
1 parent 2739b6f commit e8717d2
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
// e.g. 'single' or 'multi'.
@Input() selectionType: string = undefined;

// If `true` selected item details will be updated on table refresh
@Input() updateSelectionOnRefresh = false;

/**
* Should be a function to update the input data if undefined nothing will be triggered
*
Expand Down Expand Up @@ -214,6 +217,27 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
}
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() {
Expand Down

0 comments on commit e8717d2

Please sign in to comment.