瀏覽代碼

Table: Add clear sort

lirilsu 7 年之前
父節點
當前提交
ec182424ad
共有 2 個文件被更改,包括 26 次插入6 次删除
  1. 22 6
      packages/table/src/table-store.js
  2. 4 0
      packages/table/src/table.vue

+ 22 - 6
packages/table/src/table-store.js

@@ -150,14 +150,16 @@ TableStore.prototype.mutations = {
     Vue.nextTick(() => this.table.updateScrollY());
   },
 
-  changeSortCondition(states) {
+  changeSortCondition(states, options) {
     states.data = sortData((states.filteredData || states._data || []), states);
 
-    this.table.$emit('sort-change', {
-      column: this.states.sortingColumn,
-      prop: this.states.sortProp,
-      order: this.states.sortOrder
-    });
+    if (!options || !options.silent) {
+      this.table.$emit('sort-change', {
+        column: this.states.sortingColumn,
+        prop: this.states.sortProp,
+        order: this.states.sortOrder
+      });
+    }
 
     Vue.nextTick(() => this.table.updateScrollY());
   },
@@ -435,6 +437,20 @@ TableStore.prototype.clearFilter = function() {
   this.table.$emit('filter-clear');
 };
 
+TableStore.prototype.clearSort = function() {
+  const states = this.states;
+  if (!states.sortingColumn) return;
+  states.sortingColumn.order = null;
+  states.sortProp = null;
+  states.sortOrder = null;
+
+  this.commit('changeSortCondition', {
+    silent: true
+  });
+
+  this.table.$emit('sort-clear');
+};
+
 TableStore.prototype.updateAllSelected = function() {
   const states = this.states;
   const { selection, rowKey, selectable, data } = states;

+ 4 - 0
packages/table/src/table.vue

@@ -250,6 +250,10 @@
         this.store.clearFilter();
       },
 
+      clearSort() {
+        this.store.clearSort();
+      },
+
       handleMouseLeave() {
         this.store.commit('setHoverRow', null);
         if (this.hoverState) this.hoverState = null;