From c9bbe51500820e6b64893f9a6c45785b0badd9ee Mon Sep 17 00:00:00 2001 From: "bai.jingfeng" Date: Sun, 7 Apr 2024 18:59:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8A=E6=B8=B8=E8=B7=9F=E8=BF=9B,(fi?= =?UTF-8?q?x:=20sort=20params=20missing=20when=20switch=20page=20numbers?= =?UTF-8?q?=20#3906)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../table/hooks/useTableBlockProps.tsx | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/modules/blocks/data-blocks/table/hooks/useTableBlockProps.tsx b/packages/core/client/src/modules/blocks/data-blocks/table/hooks/useTableBlockProps.tsx index 7c20b5324..651604400 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/table/hooks/useTableBlockProps.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/table/hooks/useTableBlockProps.tsx @@ -1,6 +1,6 @@ import { ArrayField } from '@nocobase/schema'; import { useField, useFieldSchema } from '@nocobase/schema'; -import { useEffect } from 'react'; +import { useCallback, useEffect, useMemo } from 'react'; import { useFilterBlock } from '../../../../../filter-provider/FilterProvider'; import { mergeFilter } from '../../../../../filter-provider/utils'; import { removeNullCondition } from '../../../../../schema-component'; @@ -13,6 +13,7 @@ export const useTableBlockProps = () => { const ctx = useTableBlockContext(); const globalSort = fieldSchema.parent?.['x-decorator-props']?.['params']?.['sort']; const { getDataBlocks } = useFilterBlock(); + const params = ctx?.service?.params; useEffect(() => { if (!ctx?.service?.loading) { @@ -53,10 +54,20 @@ export const useTableBlockProps = () => { }); ctx.service.refresh(); }, - onChange({ current, pageSize }, filters, sorter) { - const sort = sorter.order ? (sorter.order === `ascend` ? [sorter.field] : [`-${sorter.field}`]) : globalSort; - ctx.service.run({ ...ctx.service.params?.[0], page: current, pageSize, sort }); - }, + onChange: useCallback( + ({ current, pageSize }, filters, sorter) => { + const sort = !ctx.dragSort + ? sorter.order + ? sorter.order === `ascend` + ? [sorter.field] + : [`-${sorter.field}`] + : globalSort || ctx.dragSortBy + : ctx.dragSortBy; + + ctx.service.run({ ...params?.[0], page: current, pageSize, sort }); + }, + [globalSort, params], + ), onClickRow(record, setSelectedRow, selectedRow) { const { targets, uid } = findFilterTargets(fieldSchema); const dataBlocks = getDataBlocks();