Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/oui-datagrid/src/datagrid.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ export default class DatagridController {
if (!angular.equals(this.previousRows, this.rows)) {
this.previousRows = angular.copy(this.rows);

if (this.rows && this.paging) {
// Prevent recall this if there is no page change.
// this.paging.preventLoadingRows is true if there has been no page
// or page size change since last call.
if (this.rows && this.paging && !this.paging.preventLoadingRows) {
this.refreshData(() => this.paging.setRows(this.rows));
}
}
Expand Down
11 changes: 9 additions & 2 deletions packages/oui-datagrid/src/paging/datagrid-local-paging.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default class DatagridLocalPaging extends DatagridPagingAbstract {

this.rows = rows;
this.rowLoader = rowLoader;

this.totalCount = rows ? rows.length : 0;
}

Expand All @@ -28,7 +27,15 @@ export default class DatagridLocalPaging extends DatagridPagingAbstract {
}
})
.then(result => {
this.loadRowsData(result.data);
this.preventLoadingRows = true;
this.loadRowsData(result.data)
.finally(() => {
// Delay the change of the value to prevent $doCheck of DatagridController
// calling refreshData for the last update.
this.$timeout(() => {
this.preventLoadingRows = false;
});
});
this.totalCount = result.meta.totalCount;

return result;
Expand Down
11 changes: 9 additions & 2 deletions packages/oui-datagrid/src/paging/datagrid-paging-abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export default class DatagridPagingAbstract {
this.rowLoader = rowLoader;

this.$q = pagingService.$q;
this.$timeout = pagingService.$timeout;
this.orderByFilter = pagingService.orderByFilter;

this.preventLoadingRows = false;
}

setOffset (offset) {
Expand Down Expand Up @@ -69,10 +72,10 @@ export default class DatagridPagingAbstract {

loadRowsData (rows) {
if (!this.rowLoader) {
return;
return this.$q.when();
}

rows.forEach(row => this.loadRowData(row));
return this.$q.all(rows.map(row => this.loadRowData(row)));
}

loadRowData (row) {
Expand All @@ -83,9 +86,13 @@ export default class DatagridPagingAbstract {
delete row.$promise;
});

return row.$promise;

// TODO: Find a way to forward those error to datagrid
/* .catch(this.handleError.bind(this)) */
}

return this.$q.when();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import DatagridLocalPaging from "./datagrid-local-paging";
import DatagridRemotePaging from "./datagrid-remote-paging";

export default class {
constructor ($q, orderByFilter) {
constructor ($q, $timeout, orderByFilter) {
"ngInject";

this.$q = $q;
this.$timeout = $timeout;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set, but not used in the Class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in DatagridLocalPaging.

this.orderByFilter = orderByFilter;
}

Expand Down