@polaritybit/smart-table
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -194,2 +194,5 @@ import { jsx, jsxs } from 'react/jsx-runtime'; | ||
useEffect(() => { | ||
if (!items || items.length === 0) { | ||
return; | ||
} | ||
if (typeof predicate === "function") { | ||
@@ -268,5 +271,11 @@ const sortByPredicate = sort(sortDirectionFn(predicate)); | ||
onPageChange, | ||
serverSideSorting = false, | ||
onSortChange, | ||
config | ||
}) { | ||
const _config = useConfig(config); | ||
const stableOnSortChange = useStableCallback( | ||
onSortChange ?? (() => { | ||
}) | ||
); | ||
const [sortProperties, setSortProperties] = useState({ | ||
@@ -278,3 +287,3 @@ property: defaultSortProperties?.property ?? getItemKey, | ||
const { pageItems, pageCount, activePage, setActivePage } = usePagination({ | ||
items: sortedItems, | ||
items: serverSideSorting ? items : sortedItems, | ||
options: paginationOptions, | ||
@@ -288,2 +297,5 @@ onPageChange | ||
}, [items, setActivePage, paginationOptions?.totalItems]); | ||
useEffect(() => { | ||
stableOnSortChange?.(sortProperties); | ||
}, [sortProperties, stableOnSortChange]); | ||
const handleSortPropertyChange = useCallback( | ||
@@ -290,0 +302,0 @@ function handleSortPropertyChange2(property) { |
@@ -5,4 +5,3 @@ export declare enum SortDirection { | ||
} | ||
export type SortPredicateResult<T> = ((item: T) => string | number) | string | string[]; | ||
export type SortPredicate<T = any> = SortPredicateResult<T>; | ||
export type SortPredicate<T = any> = ((item: T) => string | number) | string | string[]; | ||
export declare const useSort: <T>(items: T[], predicate: SortPredicate, direction: SortDirection) => T[]; |
@@ -1,2 +0,2 @@ | ||
import { SortDirection, SortPredicate, SortPredicateResult } from './hooks/use-sort.hook'; | ||
import { SortDirection, SortPredicate } from './hooks/use-sort.hook'; | ||
import { DeepPartial, SmartTableConfig } from './smart-table-config.context'; | ||
@@ -12,3 +12,3 @@ export declare const DEFAULT_PAGE_SIZE = 25; | ||
getValue?: (item: T, index: number, items: T[]) => React.ReactNode; | ||
getSortProperty?: SortPredicateResult<T>; | ||
getSortProperty?: SortPredicate<T>; | ||
width?: number | string; | ||
@@ -46,5 +46,7 @@ headerClassName?: string; | ||
paginationOptions?: PaginationOptions; | ||
serverSideSorting?: boolean; | ||
onSortChange?: (sortProperty: SortProperties<T>) => void; | ||
onPageChange?: (page: number) => void; | ||
}; | ||
export declare function TableHeader<T>({ column, sortProperties, onSort, config }: TableHeaderProps<T>): JSX.Element; | ||
export declare function SmartTable<T extends Record<string, unknown>>({ columns, items, getItemKey, tableClassName, rowClassName, commonCellClassName, headerRowClassName, onRowClick, parseDatasetValue, defaultSortProperties, paginationOptions, onPageChange, config, }: TableProps<T>): JSX.Element; | ||
export declare function SmartTable<T extends Record<string, unknown>>({ columns, items, getItemKey, tableClassName, rowClassName, commonCellClassName, headerRowClassName, onRowClick, parseDatasetValue, defaultSortProperties, paginationOptions, onPageChange, serverSideSorting, onSortChange, config, }: TableProps<T>): JSX.Element; |
{ | ||
"name": "@polaritybit/smart-table", | ||
"private": false, | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
@@ -9,6 +9,4 @@ import { sort, prop, path, ascend, descend } from 'ramda' | ||
export type SortPredicateResult<T> = ((item: T) => string | number) | string | string[] | ||
export type SortPredicate<T = any> = ((item: T) => string | number) | string | string[] | ||
export type SortPredicate<T = any> = SortPredicateResult<T> | ||
export const useSort = <T>(items: T[], predicate: SortPredicate, direction: SortDirection) => { | ||
@@ -21,2 +19,6 @@ const [sortedItems, setSortedItems] = useState(items || []) | ||
useEffect(() => { | ||
if (!items || items.length === 0) { | ||
return | ||
} | ||
if (typeof predicate === 'function') { | ||
@@ -23,0 +25,0 @@ const sortByPredicate = sort(sortDirectionFn(predicate)) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62761
1417