mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-09 04:31:35 +08:00
feat(table): best practices finished
This commit is contained in:
parent
df1fd15a98
commit
ea5cdc056a
@ -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,
|
||||
|
@ -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({
|
||||
|
@ -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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user