Sfoglia il codice sorgente

Table: not emit triggers sort-change during initialization (#14625)

peanut 6 anni fa
parent
commit
1967cd2b9e
2 ha cambiato i file con 7 aggiunte e 4 eliminazioni
  1. 2 1
      packages/table/src/table-header.js
  2. 5 3
      packages/table/src/table-store.js

+ 2 - 1
packages/table/src/table-header.js

@@ -210,7 +210,8 @@ export default {
 
   mounted() {
     const { prop, order } = this.defaultSort;
-    this.store.commit('sort', { prop, order });
+    const init = true;
+    this.store.commit('sort', { prop, order, init });
   },
 
   beforeDestroy() {

+ 5 - 3
packages/table/src/table-store.js

@@ -259,7 +259,7 @@ TableStore.prototype.mutations = {
   changeSortCondition(states, options) {
     states.data = sortData((states.filteredData || states._data || []), states);
 
-    if (!options || !options.silent) {
+    if (!options || !(options.silent || options.init)) {
       this.table.$emit('sort-change', {
         column: this.states.sortingColumn,
         prop: this.states.sortProp,
@@ -271,7 +271,7 @@ TableStore.prototype.mutations = {
   },
 
   sort(states, options) {
-    const { prop, order } = options;
+    const { prop, order, init } = options;
     if (prop) {
       states.sortProp = prop;
       states.sortOrder = order || 'ascending';
@@ -286,7 +286,9 @@ TableStore.prototype.mutations = {
         }
 
         if (states.sortingColumn) {
-          this.commit('changeSortCondition');
+          this.commit('changeSortCondition', {
+            init: init
+          });
         }
       });
     }