From ea5cdc056a98308c28fb5f4c3df9a2468e315baa Mon Sep 17 00:00:00 2001 From: JiwenBai Date: Mon, 16 Dec 2019 11:00:51 +0800 Subject: [PATCH] feat(table): best practices finished --- .../components/table/enUS/bestPractices.md | 9 ++++- .../components/table/enUS/filterAndSorter.md | 8 ++--- packages/common/AdvanceTable/src/main.vue | 35 ++++++++++--------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/demo/documentation/components/table/enUS/bestPractices.md b/demo/documentation/components/table/enUS/bestPractices.md index 3eabd92a3..fab3a992a 100644 --- a/demo/documentation/components/table/enUS/bestPractices.md +++ b/demo/documentation/components/table/enUS/bestPractices.md @@ -180,11 +180,12 @@ export default { const sorter = query.sorter ? JSON.parse(query.sorter) : null; const filter = query.filter ? JSON.parse(query.filter) : null; this.fetchData(page, sorter, filter); - this.$refs.table.page(page); // this.$refs.table.sorter(sorter) : null); console.warn("TCL: getDataByQuey -> filter", filter); + this.$refs.table.page(page); this.$refs.table.filter(filter); + this.$refs.table.sort(sorter.field, sorter.order); }, apiGetData(params = {}) { this.loading = true; @@ -258,6 +259,12 @@ export default { }, this.$route ); + sorter = sorter + ? { + field: sorter.field, + order: sorter.order + } + : null; if (window.location.pathname) this.$router.push({ ...this.$route, diff --git a/demo/documentation/components/table/enUS/filterAndSorter.md b/demo/documentation/components/table/enUS/filterAndSorter.md index 382afe01c..91fbfbfca 100644 --- a/demo/documentation/components/table/enUS/filterAndSorter.md +++ b/demo/documentation/components/table/enUS/filterAndSorter.md @@ -127,14 +127,14 @@ export default { console.log(filter, sorter, pagination); }, sortName() { - this.$refs.table.sort("name", "ascend", false); + this.$refs.table.sort("name", "ascend", true); }, clearFilters() { - this.$refs.table.filter(null, false); + this.$refs.table.filter(null, true); }, clearFiltersAndSorters() { - this.$refs.table.filter(null, false); - this.$refs.table.sort(null, false); + this.$refs.table.filter(null, true); + this.$refs.table.sort(null, true); }, tryRoute() { this.$router.push({ diff --git a/packages/common/AdvanceTable/src/main.vue b/packages/common/AdvanceTable/src/main.vue index 74606e112..cdd84bcce 100644 --- a/packages/common/AdvanceTable/src/main.vue +++ b/packages/common/AdvanceTable/src/main.vue @@ -248,7 +248,7 @@ export default { }, data () { return { - isOnlyViewChange: false, + triggerOnChange: false, headerHeight: 0, copyData: [], sortIndexs: {}, @@ -641,16 +641,17 @@ export default { } }) }, - page (pageNum, isOnlyViewChange = true) { - this.isOnlyViewChange = isOnlyViewChange + page (pageNum, triggerOnChange = false) { + this.triggerOnChange = triggerOnChange - this.currentPage = pageNum this.$nextTick(() => { - this.isOnlyViewChange = !isOnlyViewChange + this.currentPage = pageNum + + this.triggerOnChange = !triggerOnChange }) }, - sort (columnKey, order, isOnlyViewChange = true) { - this.isOnlyViewChange = isOnlyViewChange + sort (columnKey, order, triggerOnChange = false) { + this.triggerOnChange = triggerOnChange if (columnKey == null) { this.clearSort() @@ -658,11 +659,11 @@ export default { } this.$set(this.sortIndexs, columnKey, sortOrderMap[order]) this.$nextTick(() => { - this.isOnlyViewChange = !isOnlyViewChange + this.triggerOnChange = !triggerOnChange }) }, - filter (filterOptions, isOnlyViewChange = true) { - this.isOnlyViewChange = isOnlyViewChange + filter (filterOptions, triggerOnChange = false) { + this.triggerOnChange = triggerOnChange if (filterOptions === null) { this.selectedFilter = {} @@ -677,10 +678,14 @@ export default { this.selectedFilter = filterOptions this.$nextTick(() => { - this.isOnlyViewChange = !isOnlyViewChange + this.triggerOnChange = !triggerOnChange }) }, - setParams ({ filter, sorter, page }) { + /** + * @deprecated + * 废弃的, + */ + _setParams ({ filter, sorter, page }) { if (sorter) { this.sort(sorter.key, sorter.order) } else { @@ -814,7 +819,7 @@ export default { // return isCustom ? this.currentSortColumn : null // }, useRemoteChange () { - if (this.isOnlyViewChange) return + if (!this.triggerOnChange) return clearTimeout(this.remoteTimter) this.remoteTimter = setTimeout(() => { @@ -849,10 +854,6 @@ export default { this.processedData = [] } Object.keys(this.currentFilterColumn).forEach(key => { - console.log( - 'TCL: computeShowingData -> this.currentFilterColumn', - this.currentFilterColumn - ) const { value, filterFn } = this.currentFilterColumn[key] if (value && filterFn !== 'custom' && filterFn) { data = data.filter(item => {