diff --git a/packages/oui-datagrid/src/datagrid.controller.js b/packages/oui-datagrid/src/datagrid.controller.js index f58dece5..44b469b4 100644 --- a/packages/oui-datagrid/src/datagrid.controller.js +++ b/packages/oui-datagrid/src/datagrid.controller.js @@ -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)); } } diff --git a/packages/oui-datagrid/src/paging/datagrid-local-paging.js b/packages/oui-datagrid/src/paging/datagrid-local-paging.js index fd86b274..24253018 100644 --- a/packages/oui-datagrid/src/paging/datagrid-local-paging.js +++ b/packages/oui-datagrid/src/paging/datagrid-local-paging.js @@ -6,7 +6,6 @@ export default class DatagridLocalPaging extends DatagridPagingAbstract { this.rows = rows; this.rowLoader = rowLoader; - this.totalCount = rows ? rows.length : 0; } @@ -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; diff --git a/packages/oui-datagrid/src/paging/datagrid-paging-abstract.js b/packages/oui-datagrid/src/paging/datagrid-paging-abstract.js index 4af54f82..6ecaff18 100644 --- a/packages/oui-datagrid/src/paging/datagrid-paging-abstract.js +++ b/packages/oui-datagrid/src/paging/datagrid-paging-abstract.js @@ -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) { @@ -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) { @@ -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(); } /** diff --git a/packages/oui-datagrid/src/paging/datagrid-paging.service.js b/packages/oui-datagrid/src/paging/datagrid-paging.service.js index b7a50dba..586dc4c6 100644 --- a/packages/oui-datagrid/src/paging/datagrid-paging.service.js +++ b/packages/oui-datagrid/src/paging/datagrid-paging.service.js @@ -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; this.orderByFilter = orderByFilter; }