Skip to content

Commit 9a29f92

Browse files
albanmmarcosmoura
authored andcommitted
add watchable sort parameters in md-table (vuematerial#505)
1 parent 5d3091a commit 9a29f92

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

docs/src/pages/components/Table.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
</md-button>
338338
</md-toolbar>
339339

340-
<md-table md-sort="dessert" md-sort-type="desc" @select="onSelect" @sort="onSort">
340+
<md-table :md-sort="sortInput.name" :md-sort-type="sortInput.type" @select="onSelect" @sort="onSort">
341341
<md-table-header>
342342
<md-table-row>
343343
<md-table-head md-sort-by="dessert">Dessert (100g serving)</md-table-head>
@@ -374,6 +374,27 @@
374374
<pre>{{ selectedData }}</pre>
375375
</div>
376376

377+
<div class="output">
378+
<h2 class="md-title">Sort input</h2>
379+
<md-input-container>
380+
<label for="sort-input-name">Name</label>
381+
<md-select name="sort-input-name" id="sort-input-name" v-model="sortInput.name">
382+
<md-option value="">None</md-option>
383+
<md-option value="dessert">Dessert</md-option>
384+
<md-option value="calories">Calories</md-option>
385+
<md-option value="fat">Fat</md-option>
386+
</md-select>
387+
</md-input-container>
388+
389+
<md-input-container>
390+
<label for="sort-input-type">Type</label>
391+
<md-select name="sort-input-type" id="sort-input-type" v-model="sortInput.type">
392+
<md-option value="asc">Ascending</md-option>
393+
<md-option value="desc">Descending</md-option>
394+
</md-select>
395+
</md-input-container>
396+
</div>
397+
377398
<div class="output">
378399
<h2 class="md-title">Current Sort</h2>
379400
<pre>{{ sort }}</pre>
@@ -716,6 +737,10 @@
716737
}
717738
],
718739
selectedData: [],
740+
sortInput: {
741+
name: 'dessert',
742+
type: 'asc'
743+
},
719744
sort: {},
720745
page: {}
721746
}),

src/components/mdTable/mdTable.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
},
4949
selectedRows() {
5050
this.numberOfSelected = Object.keys(this.selectedRows).length;
51+
},
52+
mdSort() {
53+
this.sortBy = this.mdSort;
54+
this.$emit('sortInput');
55+
},
56+
mdSortType() {
57+
this.sortType = this.mdSortType;
58+
this.$emit('sortInput');
5159
}
5260
},
5361
mounted() {

src/components/mdTable/mdTableHead.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,20 @@
6464
this.parentTable.sortType = this.sortType;
6565
this.parentTable.emitSort(this.mdSortBy);
6666
}
67+
},
68+
initSort() {
69+
if (this.hasMatchSort()) {
70+
this.sorted = true;
71+
this.sortType = this.parentTable.sortType;
72+
}
6773
}
6874
},
6975
mounted() {
7076
this.parentTable = getClosestVueParent(this.$parent, 'md-table');
71-
72-
if (this.hasMatchSort()) {
73-
this.sorted = true;
74-
this.sortType = this.parentTable.sortType;
75-
}
77+
this.initSort();
78+
this.parentTable.$on('sortInput', () => {
79+
this.initSort();
80+
});
7681
}
7782
};
7883
</script>

0 commit comments

Comments
 (0)