Commit 34781d42e8da39e7656d02fb02d6220be6d0a3fa
1 parent
456a6614
feat(Table): 支持设置默认的排序值
Showing
5 changed files
with
23 additions
and
7 deletions
src/components/Table/src/hooks/useDataSource.ts
... | ... | @@ -241,7 +241,7 @@ export function useDataSource( |
241 | 241 | } |
242 | 242 | |
243 | 243 | async function fetch(opt?: FetchParams) { |
244 | - const { api, searchInfo, fetchSetting, beforeFetch, afterFetch, useSearchForm, pagination } = | |
244 | + const { api, searchInfo, defSort, fetchSetting, beforeFetch, afterFetch, useSearchForm, pagination } = | |
245 | 245 | unref(propsRef); |
246 | 246 | if (!api || !isFunction(api)) return; |
247 | 247 | try { |
... | ... | @@ -269,6 +269,7 @@ export function useDataSource( |
269 | 269 | ...(useSearchForm ? getFieldsValue() : {}), |
270 | 270 | ...searchInfo, |
271 | 271 | ...(opt?.searchInfo ?? {}), |
272 | + ...defSort, | |
272 | 273 | ...sortInfo, |
273 | 274 | ...filterInfo, |
274 | 275 | ...(opt?.sortInfo ?? {}), | ... | ... |
src/components/Table/src/props.ts
... | ... | @@ -69,6 +69,11 @@ export const basicProps = { |
69 | 69 | type: Object as PropType<Recordable>, |
70 | 70 | default: null, |
71 | 71 | }, |
72 | + // 默认的排序参数 | |
73 | + defSort: { | |
74 | + type: Object as PropType<Recordable>, | |
75 | + default: null, | |
76 | + }, | |
72 | 77 | // 使用搜索表单 |
73 | 78 | useSearchForm: propTypes.bool, |
74 | 79 | // 表单配置 | ... | ... |
src/components/Table/src/types/table.ts
src/settings/componentSetting.ts
... | ... | @@ -24,12 +24,16 @@ export default { |
24 | 24 | // Custom general sort function |
25 | 25 | defaultSortFn: (sortInfo: SorterResult) => { |
26 | 26 | const { field, order } = sortInfo; |
27 | - return { | |
28 | - // The sort field passed to the backend you | |
29 | - field, | |
30 | - // Sorting method passed to the background asc/desc | |
31 | - order, | |
32 | - }; | |
27 | + if (field && order) { | |
28 | + return { | |
29 | + // The sort field passed to the backend you | |
30 | + field, | |
31 | + // Sorting method passed to the background asc/desc | |
32 | + order, | |
33 | + }; | |
34 | + } else { | |
35 | + return {}; | |
36 | + } | |
33 | 37 | }, |
34 | 38 | // Custom general filter function |
35 | 39 | defaultFilterFn: (data: Partial<Recordable<string[]>>) => { | ... | ... |
src/views/demo/table/UseTable.vue