chore(FE-43): add conditional to set sorting and setSorting and add manualSorting props

This commit is contained in:
ValdiANS
2025-10-04 14:25:29 +07:00
parent a2345165c1
commit 7ea599168c
+11 -2
View File
@@ -47,6 +47,7 @@ export interface TableProps<TData extends object> {
emptyContent?: ReactNode; emptyContent?: ReactNode;
sorting?: SortingState; sorting?: SortingState;
setSorting?: OnChangeFn<SortingState>; setSorting?: OnChangeFn<SortingState>;
manualSorting?: boolean;
} }
const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}]; const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}];
@@ -84,6 +85,7 @@ const Table = <TData extends object>({
emptyContent = emptyContentDefaultValue, emptyContent = emptyContentDefaultValue,
sorting, sorting,
setSorting, setSorting,
manualSorting = false,
}: TableProps<TData>) => { }: TableProps<TData>) => {
const isServerSideTable = const isServerSideTable =
totalItems !== undefined && totalItems !== undefined &&
@@ -111,11 +113,10 @@ const Table = <TData extends object>({
getSortedRowModel: getSortedRowModel(), getSortedRowModel: getSortedRowModel(),
getPaginationRowModel: getPaginationRowModel(), getPaginationRowModel: getPaginationRowModel(),
onPaginationChange: setPagination, onPaginationChange: setPagination,
onSortingChange: setSorting, manualSorting,
state: { state: {
pagination, pagination,
globalFilter: fuzzySearchValue, globalFilter: fuzzySearchValue,
sorting,
}, },
filterFns: { filterFns: {
fuzzy: fuzzyFilter, fuzzy: fuzzyFilter,
@@ -128,6 +129,14 @@ const Table = <TData extends object>({
tableOptions.getFilteredRowModel = getFilteredRowModel(); tableOptions.getFilteredRowModel = getFilteredRowModel();
} }
if (sorting && setSorting) {
tableOptions.onSortingChange = setSorting;
tableOptions.state = {
...tableOptions.state,
sorting,
};
}
const table = useReactTable(tableOptions); const table = useReactTable(tableOptions);
const { setPageSize } = table; const { setPageSize } = table;