Skip to content

Commit ef210eb

Browse files
committed
eliminated multiple sort() and pagination() calls
preventing filter() call from mounted fn if it is a server mode. Emiting on-change-query params in server mode in more sensible way
1 parent a06b065 commit ef210eb

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

src/components/VueBootstrap4Table.vue

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,9 @@ export default {
372372
373373
this.initConfig();
374374
this.initialSort();
375-
this.filter();
376-
this.paginateFilter();
375+
if (!this.server_mode) {
376+
this.filter();
377+
}
377378
this.handleShiftKey();
378379
379380
},
@@ -503,9 +504,6 @@ export default {
503504
} else {
504505
this.query.sort[result].order = this.query.sort[result].order == "asc" ? "desc" : "asc";
505506
}
506-
if (!this.server_mode) {
507-
this.sort();
508-
}
509507
},
510508
isShiftSelection(shiftKey,rowIndex){
511509
return (shiftKey == true) && (this.lastSelectedItemIndex != null) && (this.lastSelectedItemIndex != rowIndex);
@@ -806,23 +804,12 @@ export default {
806804
},
807805
808806
paginateFilter() {
809-
810807
if (this.pagination) {
811808
let start = (this.page - 1) * this.per_page;
812809
let end = start + this.per_page;
813-
if (!this.server_mode) {
814-
this.vbt_rows = this.temp_filtered_results.slice(start, end);
815-
} else {
816-
this.emitQueryParams();
817-
// this.$emit('on-change-query',cloneDeep(this.query));
818-
}
810+
this.vbt_rows = this.temp_filtered_results.slice(start, end);
819811
} else {
820-
if (!this.server_mode) {
821-
this.vbt_rows = cloneDeep(this.temp_filtered_results);
822-
} else {
823-
this.emitQueryParams();
824-
// this.$emit('on-change-query',cloneDeep(this.query));
825-
}
812+
this.vbt_rows = cloneDeep(this.temp_filtered_results);
826813
}
827814
},
828815
@@ -1075,6 +1062,14 @@ export default {
10751062
},
10761063
deep: true
10771064
},
1065+
"query.sort": {
1066+
handler: function (after, before) {
1067+
if (!this.server_mode) {
1068+
this.sort();
1069+
}
1070+
},
1071+
deep: true
1072+
},
10781073
"query.global_search": {
10791074
handler: function (newVal, oldVal) {
10801075
if (!this.server_mode) {
@@ -1093,15 +1088,22 @@ export default {
10931088
per_page: {
10941089
handler: function (newVal, oldVal) {
10951090
if (!this.server_mode) {
1091+
let doPaginateFilter = (this.page == 1);
10961092
this.page = 1;
1097-
this.paginateFilter();
1093+
if (doPaginateFilter) {
1094+
this.paginateFilter();
1095+
}
1096+
} else {
1097+
this.emitQueryParams();
10981098
}
10991099
}
11001100
},
11011101
pagination: {
11021102
handler: function (newVal, oldVal) {
11031103
if (!this.server_mode) {
11041104
this.paginateFilter();
1105+
} else {
1106+
this.emitQueryParams();
11051107
}
11061108
}
11071109
},
@@ -1137,7 +1139,11 @@ export default {
11371139
return extend({}, element, extra);
11381140
});
11391141
1140-
this.filter();
1142+
if (!this.server_mode) {
1143+
this.filter();
1144+
} else {
1145+
this.emitQueryParams();
1146+
}
11411147
},
11421148
deep: true
11431149
},
@@ -1180,7 +1186,11 @@ export default {
11801186
},
11811187
11821188
page(newVal, oldVal) {
1183-
this.paginateFilter();
1189+
if (!this.server_mode) {
1190+
this.paginateFilter();
1191+
} else {
1192+
this.emitQueryParams();
1193+
}
11841194
},
11851195
'config.multi_column_sort': {
11861196
handler : function(newVal,oldVal) {

0 commit comments

Comments
 (0)