@popmenu/table 0.53.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TextFieldProps } from '@material-ui/core';
|
|
2
|
-
import { Column, ColumnFiltersState, PaginationState } from '@tanstack/react-table';
|
|
2
|
+
import { Column, ColumnFiltersState, PaginationState, SortingState } from '@tanstack/react-table';
|
|
3
3
|
import { Dispatch, SetStateAction } from 'react';
|
|
4
4
|
export interface ColumnFilter {
|
|
5
5
|
id: string;
|
|
@@ -18,6 +18,8 @@ export interface TableProps<T = unknown> {
|
|
|
18
18
|
searchable?: boolean;
|
|
19
19
|
/** Makes columns sortable. For uncontrolled sorting only. */
|
|
20
20
|
sortable?: boolean;
|
|
21
|
+
/** Sorting state. Expects the result of a React useState hook. Used only for manual sorting. */
|
|
22
|
+
sortingState?: [SortingState, Dispatch<SetStateAction<SortingState>>];
|
|
21
23
|
/** Pagination state. Expects the result of a React useState hook. Used only for manual pagination. */
|
|
22
24
|
paginationState?: [PaginationState, Dispatch<SetStateAction<PaginationState>>];
|
|
23
25
|
/** GlobalFiltering state. Expects the result of a React useState hook. Used only for manual filtering. */
|
package/build/index.es.js
CHANGED
|
@@ -3259,14 +3259,16 @@ var defaultTableProps = {
|
|
|
3259
3259
|
searchable: false,
|
|
3260
3260
|
};
|
|
3261
3261
|
var Table = function (props) {
|
|
3262
|
-
var data = props.data, columns = props.columns, loading = props.loading, searchable = props.searchable, sortable = props.sortable, externalFilterState = props.filterState, externalGlobalFilterState = props.globalFilterState, externalPaginationState = props.paginationState, externalVisibilityState = props.visibilityState, pageCount = props.pageCount, GlobalFilterProps = props.GlobalFilterProps, Empty = props.Empty;
|
|
3262
|
+
var data = props.data, columns = props.columns, loading = props.loading, searchable = props.searchable, sortable = props.sortable, externalFilterState = props.filterState, externalGlobalFilterState = props.globalFilterState, externalPaginationState = props.paginationState, externalSortingState = props.sortingState, externalVisibilityState = props.visibilityState, pageCount = props.pageCount, GlobalFilterProps = props.GlobalFilterProps, Empty = props.Empty;
|
|
3263
3263
|
var classes = useStyles$6(props);
|
|
3264
3264
|
var rootRef = useRef(null);
|
|
3265
3265
|
// Prepare Empty State
|
|
3266
3266
|
var isEmpty = data.length === 0;
|
|
3267
3267
|
var isEmptyComponentValid = Empty && isValidElement(createElement(Empty));
|
|
3268
3268
|
// Prepare Sorting
|
|
3269
|
-
var _a =
|
|
3269
|
+
var _a = externalSortingState || [], sorting = _a[0], setSorting = _a[1];
|
|
3270
|
+
var isControlledColumnSort = Boolean(externalSortingState);
|
|
3271
|
+
var controlledColumnSortOptions = { onSortingChange: setSorting, manualSorting: true };
|
|
3270
3272
|
// Prepare Global Filtering
|
|
3271
3273
|
var _b = externalGlobalFilterState || [], globalFilter = _b[0], setGlobalFilter = _b[1];
|
|
3272
3274
|
var isControlledGlobalFilter = Boolean(externalGlobalFilterState);
|
|
@@ -3283,7 +3285,7 @@ var Table = function (props) {
|
|
|
3283
3285
|
var columnVisibility = (externalVisibilityState || [])[0];
|
|
3284
3286
|
var isControlledColumnVisibility = Boolean(externalVisibilityState);
|
|
3285
3287
|
// Init table instance
|
|
3286
|
-
var table = useReactTable(__assign$3(__assign$3(__assign$3({ data: data, columns: columns, state: __assign$3(__assign$3(__assign$3(__assign$3({
|
|
3288
|
+
var table = useReactTable(__assign$3(__assign$3(__assign$3(__assign$3({ data: data, columns: columns, state: __assign$3(__assign$3(__assign$3(__assign$3(__assign$3({}, (isControlledPagination && { pagination: pagination })), (isControlledGlobalFilter && { globalFilter: globalFilter })), (isControlledColumnFilters && { columnFilters: columnFilters })), (isControlledColumnVisibility && { columnVisibility: columnVisibility })), (isControlledColumnSort && { sorting: sorting })), enableSorting: sortable, globalFilterFn: coercedValueIncludesString, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), getPaginationRowModel: getPaginationRowModel() }, (isControlledPagination && controlledPaginationOptions)), (isControlledGlobalFilter && controlledGlobalFilterOptions)), (isControlledColumnFilters && controlledColumnFiltersOptions)), (isControlledColumnSort && controlledColumnSortOptions)));
|
|
3287
3289
|
var _f = useColumnFilters(table), selectedColumnFilters = _f.selectedColumnFilters, hasColumnFilters = _f.hasColumnFilters, deselectColumnFilter = _f.deselectColumnFilter, formatSelectedFilterText = _f.formatSelectedFilterText, resetColumnFilters = _f.resetColumnFilters;
|
|
3288
3290
|
var handlePagination = function (_e, pageNumber) {
|
|
3289
3291
|
var pageIndex = pageNumber - 1;
|