fix(pagination): duplicated rows on paginate #1214
|
@ -14,6 +14,7 @@ export default class CrudModel extends ModelProxy {
|
||||||
this.$q = $q;
|
this.$q = $q;
|
||||||
this.primaryKey = 'id';
|
this.primaryKey = 'id';
|
||||||
this.autoLoad = false;
|
this.autoLoad = false;
|
||||||
|
this.page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
|
@ -125,13 +126,20 @@ export default class CrudModel extends ModelProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMore() {
|
loadMore(append) {
|
||||||
if (!this.moreRows)
|
if (!this.moreRows)
|
||||||
return this.$q.resolve();
|
return this.$q.resolve();
|
||||||
|
|
||||||
let filter = Object.assign({}, this.currentFilter);
|
const filter = Object.assign({}, this.currentFilter);
|
||||||
filter.skip = this.orgData ? this.orgData.length : 0;
|
if (append)
|
||||||
return this.sendRequest(filter, true);
|
filter.skip = this.orgData ? this.orgData.length : 0;
|
||||||
|
|
||||||
|
if (!append) {
|
||||||
|
this.page += 1;
|
||||||
|
filter.limit = this.page * this.limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.sendRequest(filter, append);
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
|
|
|
@ -148,7 +148,7 @@ describe('Component vnCrudModel', () => {
|
||||||
|
|
||||||
controller.moreRows = true;
|
controller.moreRows = true;
|
||||||
|
|
||||||
controller.loadMore();
|
controller.loadMore(true);
|
||||||
|
|
||||||
expect(controller.sendRequest).toHaveBeenCalledWith({'skip': 2}, true);
|
expect(controller.sendRequest).toHaveBeenCalledWith({'skip': 2}, true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -212,12 +212,12 @@ export default class DropDown extends Popover {
|
||||||
&& !this.model.isLoading;
|
&& !this.model.isLoading;
|
||||||
|
|
||||||
if (shouldLoad)
|
if (shouldLoad)
|
||||||
this.model.loadMore();
|
this.model.loadMore(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoadMoreClick(event) {
|
onLoadMoreClick(event) {
|
||||||
if (event.defaultPrevented) return;
|
if (event.defaultPrevented) return;
|
||||||
this.model.loadMore();
|
this.model.loadMore(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
onContainerClick(event) {
|
onContainerClick(event) {
|
||||||
|
|
|
@ -374,9 +374,10 @@ export class Paginable {
|
||||||
/**
|
/**
|
||||||
* When limit is enabled, loads the next set of rows.
|
* When limit is enabled, loads the next set of rows.
|
||||||
*
|
*
|
||||||
|
* @param {Boolean} append - Whether should append new data
|
||||||
* @return {Promise} The request promise
|
* @return {Promise} The request promise
|
||||||
*/
|
*/
|
||||||
loadMore() {
|
loadMore(append) {
|
||||||
return Promise.resolve();
|
return Promise.resolve(append);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ class Pagination extends Component {
|
||||||
|
|
||||||
if (shouldLoad) {
|
if (shouldLoad) {
|
||||||
this.nLoads++;
|
this.nLoads++;
|
||||||
this.model.loadMore();
|
this.model.loadMore(false);
|
||||||
this.$.$apply();
|
this.$.$apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ class Pagination extends Component {
|
||||||
if (this.maxLoads > 0 && this.nLoads == this.maxLoads)
|
if (this.maxLoads > 0 && this.nLoads == this.maxLoads)
|
||||||
this.nLoads = 0;
|
this.nLoads = 0;
|
||||||
|
|
||||||
this.model.loadMore();
|
this.model.loadMore(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$onDestroy() {
|
$onDestroy() {
|
||||||
|
|
|
@ -38,6 +38,7 @@ module.exports = Self => {
|
||||||
date.setHours(0, 0, 0, 0);
|
date.setHours(0, 0, 0, 0);
|
||||||
const stmt = new ParameterizedSQL(`
|
const stmt = new ParameterizedSQL(`
|
||||||
SELECT
|
SELECT
|
||||||
|
v.id,
|
||||||
u.name AS salesPerson,
|
u.name AS salesPerson,
|
||||||
IFNULL(sc.workerSubstitute, c.salesPersonFk) AS salesPersonFk,
|
IFNULL(sc.workerSubstitute, c.salesPersonFk) AS salesPersonFk,
|
||||||
c.id AS clientFk,
|
c.id AS clientFk,
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="visit in model.data">
|
<tr ng-repeat="visit in model.data track by visit.id">
|
||||||
<td shrink-date>
|
<td shrink-date>
|
||||||
<span class="chip">
|
<span class="chip">
|
||||||
{{::visit.dated | date:'dd/MM/yy'}}
|
{{::visit.dated | date:'dd/MM/yy'}}
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<vn-th field="salesPersonFk" shrink>SalesPerson</vn-th>
|
<vn-th field="salesPersonFk" shrink>SalesPerson</vn-th>
|
||||||
</vn-tr>
|
</vn-tr>
|
||||||
</vn-thead>
|
</vn-thead>
|
||||||
<a ng-repeat="order in model.data"
|
<a ng-repeat="order in model.data track by order.id"
|
||||||
class="clickable vn-tbody"
|
class="clickable vn-tbody"
|
||||||
ui-sref="order.card.summary({id: {{::order.id}}})" target="_blank">
|
ui-sref="order.card.summary({id: {{::order.id}}})" target="_blank">
|
||||||
<vn-tr>
|
<vn-tr>
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="ticket in model.data"
|
<tr ng-repeat="ticket in model.data track by ticket.id"
|
||||||
vn-anchor="::{
|
vn-anchor="::{
|
||||||
state: 'ticket.card.summary',
|
state: 'ticket.card.summary',
|
||||||
params: {id: ticket.id},
|
params: {id: ticket.id},
|
||||||
|
|
Loading…
Reference in New Issue