fix: vxeGrid default sort data no effect in first query (#5141)
* fix: vxeGrid default sort data no effect in first query * fix: query params lostdev-v5
parent
e558087bcf
commit
bedf19993d
|
@ -43,6 +43,31 @@ export default eventHandler(async (event) => {
|
||||||
|
|
||||||
await sleep(600);
|
await sleep(600);
|
||||||
|
|
||||||
const { page, pageSize } = getQuery(event);
|
const { page, pageSize, sortBy, sortOrder } = getQuery(event);
|
||||||
return usePageResponseSuccess(page as string, pageSize as string, mockData);
|
const listData = structuredClone(mockData);
|
||||||
|
if (sortBy && Reflect.has(listData[0], sortBy as string)) {
|
||||||
|
listData.sort((a, b) => {
|
||||||
|
if (sortOrder === 'asc') {
|
||||||
|
if (sortBy === 'price') {
|
||||||
|
return (
|
||||||
|
Number.parseFloat(a[sortBy as string]) -
|
||||||
|
Number.parseFloat(b[sortBy as string])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return a[sortBy as string] > b[sortBy as string] ? 1 : -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sortBy === 'price') {
|
||||||
|
return (
|
||||||
|
Number.parseFloat(b[sortBy as string]) -
|
||||||
|
Number.parseFloat(a[sortBy as string])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return a[sortBy as string] < b[sortBy as string] ? 1 : -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return usePageResponseSuccess(page as string, pageSize as string, listData);
|
||||||
});
|
});
|
||||||
|
|
|
@ -243,7 +243,8 @@ async function init() {
|
||||||
const autoLoad = defaultGridOptions.proxyConfig?.autoLoad;
|
const autoLoad = defaultGridOptions.proxyConfig?.autoLoad;
|
||||||
const enableProxyConfig = options.value.proxyConfig?.enabled;
|
const enableProxyConfig = options.value.proxyConfig?.enabled;
|
||||||
if (enableProxyConfig && autoLoad) {
|
if (enableProxyConfig && autoLoad) {
|
||||||
props.api.reload(formApi.form?.values ?? {});
|
props.api.grid.commitProxy?.('_init', formApi.form?.values ?? {});
|
||||||
|
// props.api.reload(formApi.form?.values ?? {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// form 由 vben-form代替,所以不适配formConfig,这里给出警告
|
// form 由 vben-form代替,所以不适配formConfig,这里给出警告
|
||||||
|
|
|
@ -25,10 +25,10 @@ const gridOptions: VxeGridProps<RowType> = {
|
||||||
columns: [
|
columns: [
|
||||||
{ title: '序号', type: 'seq', width: 50 },
|
{ title: '序号', type: 'seq', width: 50 },
|
||||||
{ align: 'left', title: 'Name', type: 'checkbox', width: 100 },
|
{ align: 'left', title: 'Name', type: 'checkbox', width: 100 },
|
||||||
{ field: 'category', title: 'Category' },
|
{ field: 'category', sortable: true, title: 'Category' },
|
||||||
{ field: 'color', title: 'Color' },
|
{ field: 'color', sortable: true, title: 'Color' },
|
||||||
{ field: 'productName', title: 'Product Name' },
|
{ field: 'productName', sortable: true, title: 'Product Name' },
|
||||||
{ field: 'price', title: 'Price' },
|
{ field: 'price', sortable: true, title: 'Price' },
|
||||||
{ field: 'releaseDate', formatter: 'formatDateTime', title: 'DateTime' },
|
{ field: 'releaseDate', formatter: 'formatDateTime', title: 'DateTime' },
|
||||||
],
|
],
|
||||||
exportConfig: {},
|
exportConfig: {},
|
||||||
|
@ -36,19 +36,26 @@ const gridOptions: VxeGridProps<RowType> = {
|
||||||
keepSource: true,
|
keepSource: true,
|
||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
ajax: {
|
ajax: {
|
||||||
query: async ({ page }) => {
|
query: async ({ page, sort }) => {
|
||||||
return await getExampleTableApi({
|
return await getExampleTableApi({
|
||||||
page: page.currentPage,
|
page: page.currentPage,
|
||||||
pageSize: page.pageSize,
|
pageSize: page.pageSize,
|
||||||
|
sortBy: sort.field,
|
||||||
|
sortOrder: sort.order,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
sort: true,
|
||||||
|
},
|
||||||
|
sortConfig: {
|
||||||
|
defaultSort: { field: 'category', order: 'desc' },
|
||||||
|
remote: true,
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
custom: true,
|
custom: true,
|
||||||
export: true,
|
export: true,
|
||||||
// import: true,
|
// import: true,
|
||||||
refresh: true,
|
refresh: { code: 'query' },
|
||||||
zoom: true,
|
zoom: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue