@bsol-oss/react-datatable5 1.0.64 → 2.0.1
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.
- package/dist/index.d.ts +72 -31
- package/dist/index.js +123 -103
- package/dist/index.mjs +124 -105
- package/dist/types/components/Controls/SelectAllRowsToggle.d.ts +4 -4
- package/dist/types/components/DataTable/DataTable.d.ts +18 -13
- package/dist/types/components/DataTable/DataTableContext.d.ts +3 -3
- package/dist/types/components/DataTable/DataTableServer.d.ts +18 -14
- package/dist/types/components/DataTable/useDataTable.d.ts +33 -8
- package/dist/types/components/DataTable/useDataTableContext.d.ts +8 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/types/components/DataTable.d.ts +0 -33
- package/dist/types/components/DataTableContext.d.ts +0 -10
- package/dist/types/components/DataTableServer.d.ts +0 -38
- package/dist/types/components/DefaultTable.d.ts +0 -5
- package/dist/types/components/DensityFeature.d.ts +0 -23
- package/dist/types/components/DensityToggle.d.ts +0 -1
- package/dist/types/components/DensityToggleButton.d.ts +0 -6
- package/dist/types/components/EditFilterButton.d.ts +0 -9
- package/dist/types/components/EditOrderButton.d.ts +0 -7
- package/dist/types/components/EditSortingButton.d.ts +0 -7
- package/dist/types/components/EditViewButton.d.ts +0 -7
- package/dist/types/components/FilterOptions.d.ts +0 -4
- package/dist/types/components/GlobalFilter.d.ts +0 -3
- package/dist/types/components/PageSizeControl.d.ts +0 -4
- package/dist/types/components/ResetFilteringButton.d.ts +0 -4
- package/dist/types/components/ResetSelectionButton.d.ts +0 -4
- package/dist/types/components/ResetSortingButton.d.ts +0 -4
- package/dist/types/components/RowCountText.d.ts +0 -1
- package/dist/types/components/SelectAllRowsToggle.d.ts +0 -8
- package/dist/types/components/Table.d.ts +0 -8
- package/dist/types/components/TableBody.d.ts +0 -17
- package/dist/types/components/TableCardContainer.d.ts +0 -6
- package/dist/types/components/TableCards.d.ts +0 -4
- package/dist/types/components/TableComponent.d.ts +0 -6
- package/dist/types/components/TableComponentRenderer.d.ts +0 -6
- package/dist/types/components/TableControls.d.ts +0 -13
- package/dist/types/components/TableFilter.d.ts +0 -8
- package/dist/types/components/TableFilterTags.d.ts +0 -1
- package/dist/types/components/TableFooter.d.ts +0 -7
- package/dist/types/components/TableHeader.d.ts +0 -8
- package/dist/types/components/TableLoadingComponent.d.ts +0 -5
- package/dist/types/components/TableOrderer.d.ts +0 -1
- package/dist/types/components/TablePagination.d.ts +0 -3
- package/dist/types/components/TableReloadButton.d.ts +0 -4
- package/dist/types/components/TableSelector.d.ts +0 -1
- package/dist/types/components/TableSorter.d.ts +0 -1
- package/dist/types/components/TableViewer.d.ts +0 -1
- package/dist/types/components/TextCell.d.ts +0 -10
- package/dist/types/components/useDataFromUrl.d.ts +0 -14
- package/dist/types/components/useDataTable.d.ts +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RowData, OnChangeFn, Updater, FilterFn, ColumnDef, RowSelectionState, ColumnFiltersState, SortingState, VisibilityState, Row, Table as Table$1, Column } from '@tanstack/react-table';
|
|
2
|
+
import { RowData, OnChangeFn, Updater, FilterFn, ColumnDef, RowSelectionState, ColumnOrderState, ColumnFiltersState, GlobalFilterTableState, PaginationState, SortingState, VisibilityState, Row, Table as Table$1, Column } from '@tanstack/react-table';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import React$1, { ReactNode } from 'react';
|
|
5
5
|
import { RankingInfo } from '@tanstack/match-sorter-utils';
|
|
@@ -103,19 +103,24 @@ interface DataTableProps<TData> {
|
|
|
103
103
|
enableMultiRowSelection?: boolean;
|
|
104
104
|
enableSubRowSelection?: boolean;
|
|
105
105
|
onRowSelect?: (rowSelectionState: RowSelectionState, data: TData[]) => void;
|
|
106
|
-
columnOrder
|
|
107
|
-
columnFilters
|
|
108
|
-
globalFilter
|
|
109
|
-
density
|
|
110
|
-
pagination
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
columnOrder: ColumnOrderState;
|
|
107
|
+
columnFilters: ColumnFiltersState;
|
|
108
|
+
globalFilter: GlobalFilterTableState;
|
|
109
|
+
density: DensityState;
|
|
110
|
+
pagination: PaginationState;
|
|
111
|
+
sorting: SortingState;
|
|
112
|
+
rowSelection: RowSelectionState;
|
|
113
|
+
columnVisibility: VisibilityState;
|
|
114
|
+
setPagination: OnChangeFn<PaginationState>;
|
|
115
|
+
setSorting: OnChangeFn<SortingState>;
|
|
116
|
+
setColumnFilters: OnChangeFn<ColumnFiltersState>;
|
|
117
|
+
setRowSelection: OnChangeFn<RowSelectionState>;
|
|
118
|
+
setGlobalFilter: OnChangeFn<GlobalFilterTableState>;
|
|
119
|
+
setColumnOrder: OnChangeFn<ColumnOrderState>;
|
|
120
|
+
setDensity: OnChangeFn<DensityState>;
|
|
121
|
+
setColumnVisibility: OnChangeFn<VisibilityState>;
|
|
122
|
+
}
|
|
123
|
+
declare const DataTable: <TData>({ columns, data, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, onRowSelect, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, children, }: DataTableProps<TData>) => react_jsx_runtime.JSX.Element;
|
|
119
124
|
|
|
120
125
|
interface DataTableServerProps<TData> {
|
|
121
126
|
children: JSX.Element | JSX.Element[];
|
|
@@ -125,18 +130,22 @@ interface DataTableServerProps<TData> {
|
|
|
125
130
|
enableMultiRowSelection?: boolean;
|
|
126
131
|
enableSubRowSelection?: boolean;
|
|
127
132
|
onRowSelect?: (rowSelectionState: RowSelectionState, data: TData[]) => void;
|
|
128
|
-
columnOrder
|
|
129
|
-
columnFilters
|
|
130
|
-
globalFilter
|
|
131
|
-
density
|
|
132
|
-
pagination
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
columnOrder: ColumnOrderState;
|
|
134
|
+
columnFilters: ColumnFiltersState;
|
|
135
|
+
globalFilter: GlobalFilterTableState;
|
|
136
|
+
density: DensityState;
|
|
137
|
+
pagination: PaginationState;
|
|
138
|
+
sorting: SortingState;
|
|
139
|
+
rowSelection: RowSelectionState;
|
|
140
|
+
columnVisibility: VisibilityState;
|
|
141
|
+
setPagination: OnChangeFn<PaginationState>;
|
|
142
|
+
setSorting: OnChangeFn<SortingState>;
|
|
143
|
+
setColumnFilters: OnChangeFn<ColumnFiltersState>;
|
|
144
|
+
setRowSelection: OnChangeFn<RowSelectionState>;
|
|
145
|
+
setGlobalFilter: OnChangeFn<GlobalFilterTableState>;
|
|
146
|
+
setColumnOrder: OnChangeFn<ColumnOrderState>;
|
|
147
|
+
setDensity: OnChangeFn<DensityState>;
|
|
148
|
+
setColumnVisibility: OnChangeFn<VisibilityState>;
|
|
140
149
|
}
|
|
141
150
|
interface Result<T> {
|
|
142
151
|
results: T[];
|
|
@@ -146,7 +155,7 @@ interface DataResponse<T> extends Result<T> {
|
|
|
146
155
|
count: number;
|
|
147
156
|
filterCount: number;
|
|
148
157
|
}
|
|
149
|
-
declare const DataTableServer: <TData>({ columns, url, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, onRowSelect, columnOrder
|
|
158
|
+
declare const DataTableServer: <TData>({ columns, url, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, onRowSelect, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, children, }: DataTableServerProps<TData>) => react_jsx_runtime.JSX.Element;
|
|
150
159
|
|
|
151
160
|
interface TableControlsProps {
|
|
152
161
|
totalText?: string;
|
|
@@ -272,11 +281,43 @@ interface useDataFromUrlProps<T> {
|
|
|
272
281
|
}
|
|
273
282
|
declare const useDataFromUrl: <T>({ url, params, disableFirstFetch, onFetchSuccess, defaultData, }: useDataFromUrlProps<T>) => useDataFromUrlReturn<T>;
|
|
274
283
|
|
|
275
|
-
|
|
284
|
+
interface UseDataTableProps {
|
|
285
|
+
default: {
|
|
286
|
+
sorting?: SortingState;
|
|
287
|
+
columnFilters?: ColumnFiltersState;
|
|
288
|
+
pagination?: PaginationState;
|
|
289
|
+
rowSelection?: RowSelectionState;
|
|
290
|
+
columnOrder?: ColumnOrderState;
|
|
291
|
+
globalFilter?: GlobalFilterTableState;
|
|
292
|
+
columnVisibility?: VisibilityState;
|
|
293
|
+
density?: DensityState;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
interface UseDataTableReturn {
|
|
297
|
+
sorting: SortingState;
|
|
298
|
+
columnFilters: ColumnFiltersState;
|
|
299
|
+
pagination: PaginationState;
|
|
300
|
+
rowSelection: RowSelectionState;
|
|
301
|
+
columnOrder: ColumnOrderState;
|
|
302
|
+
globalFilter: GlobalFilterTableState;
|
|
303
|
+
columnVisibility: VisibilityState;
|
|
304
|
+
density: DensityState;
|
|
305
|
+
setPagination: OnChangeFn<PaginationState>;
|
|
306
|
+
setSorting: OnChangeFn<SortingState>;
|
|
307
|
+
setColumnFilters: OnChangeFn<ColumnFiltersState>;
|
|
308
|
+
setRowSelection: OnChangeFn<RowSelectionState>;
|
|
309
|
+
setGlobalFilter: OnChangeFn<GlobalFilterTableState>;
|
|
310
|
+
setColumnOrder: OnChangeFn<ColumnOrderState>;
|
|
311
|
+
setDensity: OnChangeFn<DensityState>;
|
|
312
|
+
setColumnVisibility: OnChangeFn<VisibilityState>;
|
|
313
|
+
}
|
|
314
|
+
declare const useDataTable: ({ default: { sorting: defaultSorting, pagination: defaultPagination, rowSelection: defaultRowSelection, columnFilters: defaultColumnFilters, columnOrder: defaultColumnOrder, columnVisibility: defaultColumnVisibility, globalFilter: defaultGlobalFilter, density: defaultDensity, }, }?: UseDataTableProps) => UseDataTableReturn;
|
|
315
|
+
|
|
316
|
+
declare const useDataTableContext: () => {
|
|
276
317
|
table: _tanstack_table_core.Table<any>;
|
|
277
318
|
refreshData: () => void;
|
|
278
|
-
globalFilter:
|
|
279
|
-
setGlobalFilter:
|
|
319
|
+
globalFilter: _tanstack_table_core.GlobalFilterTableState;
|
|
320
|
+
setGlobalFilter: _tanstack_table_core.OnChangeFn<_tanstack_table_core.GlobalFilterTableState>;
|
|
280
321
|
loading: boolean;
|
|
281
322
|
hasError: boolean;
|
|
282
323
|
};
|
|
@@ -342,4 +383,4 @@ declare module "@tanstack/react-table" {
|
|
|
342
383
|
}
|
|
343
384
|
}
|
|
344
385
|
|
|
345
|
-
export { type DataResponse, DataTable, type DataTableProps, DataTableServer, type DataTableServerProps, DefaultTable, type DefaultTableProps, DensityToggleButton, type DensityToggleButtonProps, EditFilterButton, type EditFilterButtonProps, EditOrderButton, type EditOrderButtonProps, EditSortingButton, type EditSortingButtonProps, EditViewButton, type EditViewButtonProps, FilterOptions, type FilterOptionsProps, GlobalFilter, PageSizeControl, type PageSizeControlProps, type PaginationProps, ReloadButton, type ReloadButtonProps, ResetFilteringButton, type ResetFilteringButtonProps, ResetSelectionButton, type ResetSelectionButtonProps, ResetSortingButton, type ResetSortingButtonProps, type Result, RowCountText, Table, TableBody, type TableBodyProps, TableCardContainer, type TableCardContainerProps, TableCards, type TableCardsProps, TableComponent, TableControls, type TableControlsProps, TableFilter, TableFilterTags, TableFooter, type TableFooterProps, TableHeader, type TableHeaderProps, TableLoadingComponent, type TableLoadingComponentProps, TableOrderer, TablePagination, type TableProps, type TableRendererProps, type TableRowSelectorProps, TableSelector, TableSorter, TableViewer, TextCell, type TextCellProps, useDataFromUrl, type useDataFromUrlProps, type useDataFromUrlReturn, useDataTable };
|
|
386
|
+
export { type DataResponse, DataTable, type DataTableProps, DataTableServer, type DataTableServerProps, DefaultTable, type DefaultTableProps, DensityToggleButton, type DensityToggleButtonProps, EditFilterButton, type EditFilterButtonProps, EditOrderButton, type EditOrderButtonProps, EditSortingButton, type EditSortingButtonProps, EditViewButton, type EditViewButtonProps, FilterOptions, type FilterOptionsProps, GlobalFilter, PageSizeControl, type PageSizeControlProps, type PaginationProps, ReloadButton, type ReloadButtonProps, ResetFilteringButton, type ResetFilteringButtonProps, ResetSelectionButton, type ResetSelectionButtonProps, ResetSortingButton, type ResetSortingButtonProps, type Result, RowCountText, Table, TableBody, type TableBodyProps, TableCardContainer, type TableCardContainerProps, TableCards, type TableCardsProps, TableComponent, TableControls, type TableControlsProps, TableFilter, TableFilterTags, TableFooter, type TableFooterProps, TableHeader, type TableHeaderProps, TableLoadingComponent, type TableLoadingComponentProps, TableOrderer, TablePagination, type TableProps, type TableRendererProps, type TableRowSelectorProps, TableSelector, TableSorter, TableViewer, TextCell, type TextCellProps, type UseDataTableProps, type UseDataTableReturn, useDataFromUrl, type useDataFromUrlProps, type useDataFromUrlReturn, useDataTable, useDataTableContext };
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var reactBeautifulDnd = require('react-beautiful-dnd');
|
|
|
18
18
|
var fa = require('react-icons/fa');
|
|
19
19
|
|
|
20
20
|
const DensityToggleButton = ({ text, icon = jsxRuntime.jsx(ai.AiOutlineColumnWidth, {}), }) => {
|
|
21
|
-
const { table } =
|
|
21
|
+
const { table } = useDataTableContext();
|
|
22
22
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "Toggle Density", icon: icon, onClick: () => {
|
|
23
23
|
table.toggleDensity();
|
|
24
24
|
} })), !!text !== false && (jsxRuntime.jsx(react.Button, { leftIcon: icon, variant: "ghost", "aria-label": "Toggle Density", onClick: () => {
|
|
@@ -39,13 +39,13 @@ const EditOrderButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineMoveDown, {})
|
|
|
39
39
|
const TableContext = react$1.createContext({
|
|
40
40
|
table: {},
|
|
41
41
|
refreshData: () => { },
|
|
42
|
-
globalFilter: "",
|
|
42
|
+
globalFilter: { globalFilter: "" },
|
|
43
43
|
setGlobalFilter: () => { },
|
|
44
44
|
loading: false,
|
|
45
45
|
hasError: false,
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
const
|
|
48
|
+
const useDataTableContext = () => {
|
|
49
49
|
const { table, refreshData, globalFilter, setGlobalFilter, loading, hasError, } = react$1.useContext(TableContext);
|
|
50
50
|
return {
|
|
51
51
|
table,
|
|
@@ -58,20 +58,14 @@ const useDataTable = () => {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
const TableSorter = () => {
|
|
61
|
-
const { table } =
|
|
61
|
+
const { table } = useDataTableContext();
|
|
62
62
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsx(jsxRuntime.Fragment, { children: headerGroup.headers.map((header) => {
|
|
63
63
|
const displayName = header.column.columnDef.meta === undefined
|
|
64
64
|
? header.column.id
|
|
65
65
|
: header.column.columnDef.meta.displayName;
|
|
66
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: header.column.getCanSort() && (jsxRuntime.jsxs(react.Flex, { alignItems: "center", gap: "0.5rem", padding: "0.5rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsxs(react.Button, { variant: "ghost", onClick: (
|
|
66
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: header.column.getCanSort() && (jsxRuntime.jsxs(react.Flex, { alignItems: "center", gap: "0.5rem", padding: "0.5rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsxs(react.Button, { variant: "ghost", onClick: () => {
|
|
67
67
|
header.column.toggleSorting();
|
|
68
|
-
}, children: [header.column.getIsSorted() === false && (
|
|
69
|
-
// <Text>To No sort</Text>
|
|
70
|
-
jsxRuntime.jsx(icons.UpDownIcon, {})), header.column.getIsSorted() === "asc" && (
|
|
71
|
-
// <Text>To asc</Text>
|
|
72
|
-
jsxRuntime.jsx(icons.ChevronDownIcon, {})), header.column.getIsSorted() === "desc" && (
|
|
73
|
-
// <Text>To desc</Text>
|
|
74
|
-
jsxRuntime.jsx(icons.ChevronUpIcon, {}))] }), header.column.getIsSorted() && (jsxRuntime.jsx(react.Button, { onClick: (e) => {
|
|
68
|
+
}, children: [header.column.getIsSorted() === false && jsxRuntime.jsx(icons.UpDownIcon, {}), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(icons.ChevronDownIcon, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(icons.ChevronUpIcon, {}))] }), header.column.getIsSorted() && (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
75
69
|
header.column.clearSorting();
|
|
76
70
|
}, children: jsxRuntime.jsx(icons.CloseIcon, {}) }))] })) }));
|
|
77
71
|
}) }))) }));
|
|
@@ -88,35 +82,35 @@ const EditViewButton = ({ text, icon = jsxRuntime.jsx(io.IoMdEye, {}), title = "
|
|
|
88
82
|
};
|
|
89
83
|
|
|
90
84
|
const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
|
|
91
|
-
const { table } =
|
|
85
|
+
const { table } = useDataTableContext();
|
|
92
86
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(react.Menu, { children: [jsxRuntime.jsx(react.MenuButton, { as: react.Button, variant: "ghost", rightIcon: jsxRuntime.jsx(icons.ChevronDownIcon, {}), gap: "0.5rem", children: table.getState().pagination.pageSize }), jsxRuntime.jsx(react.MenuList, { children: pageSizes.map((pageSize) => (jsxRuntime.jsx(react.MenuItem, { onClick: () => {
|
|
93
87
|
table.setPageSize(Number(pageSize));
|
|
94
88
|
}, children: pageSize }, crypto.randomUUID()))) })] }) }));
|
|
95
89
|
};
|
|
96
90
|
|
|
97
91
|
const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
|
|
98
|
-
const { table } =
|
|
92
|
+
const { table } = useDataTableContext();
|
|
99
93
|
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
100
94
|
table.resetColumnFilters();
|
|
101
95
|
}, children: text }));
|
|
102
96
|
};
|
|
103
97
|
|
|
104
98
|
const ResetSelectionButton = ({ text = "Reset Selection", }) => {
|
|
105
|
-
const { table } =
|
|
99
|
+
const { table } = useDataTableContext();
|
|
106
100
|
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
107
101
|
table.resetRowSelection();
|
|
108
102
|
}, children: text }));
|
|
109
103
|
};
|
|
110
104
|
|
|
111
105
|
const ResetSortingButton = ({ text = "Reset Sorting", }) => {
|
|
112
|
-
const { table } =
|
|
106
|
+
const { table } = useDataTableContext();
|
|
113
107
|
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
114
108
|
table.resetSorting();
|
|
115
109
|
}, children: text }));
|
|
116
110
|
};
|
|
117
111
|
|
|
118
112
|
const RowCountText = () => {
|
|
119
|
-
const { table } =
|
|
113
|
+
const { table } = useDataTableContext();
|
|
120
114
|
return jsxRuntime.jsx(react.Text, { children: table.getRowCount() });
|
|
121
115
|
};
|
|
122
116
|
|
|
@@ -204,15 +198,7 @@ const fuzzyFilter = (row, columnId, value, addMeta) => {
|
|
|
204
198
|
// Return if the item should be filtered in/out
|
|
205
199
|
return itemRank.passed;
|
|
206
200
|
};
|
|
207
|
-
const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder
|
|
208
|
-
pageIndex: 0, //initial page index
|
|
209
|
-
pageSize: 10, //default page size
|
|
210
|
-
}, sorting: defaultSorting = [], rowSelection: defaultRowSelection = {}, columnVisibility: defaultColumnVisibility = {}, children, }) => {
|
|
211
|
-
const [columnOrder, setColumnOrder] = react$1.useState(defaultColumnOrder);
|
|
212
|
-
const [globalFilter, setGlobalFilter] = react$1.useState(defaultGlobalFilter);
|
|
213
|
-
const [densityState, setDensity] = react$1.useState(density);
|
|
214
|
-
const [rowSelection, setRowSelection] = react$1.useState(defaultRowSelection);
|
|
215
|
-
const [columnVisibility, setColumnVisibility] = react$1.useState(defaultColumnVisibility);
|
|
201
|
+
const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, children, }) => {
|
|
216
202
|
const table = reactTable.useReactTable({
|
|
217
203
|
_features: [DensityFeature],
|
|
218
204
|
data: data,
|
|
@@ -226,16 +212,6 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
226
212
|
minSize: 10, //enforced during column resizing
|
|
227
213
|
maxSize: 10000, //enforced during column resizing
|
|
228
214
|
},
|
|
229
|
-
state: {
|
|
230
|
-
columnOrder,
|
|
231
|
-
globalFilter,
|
|
232
|
-
density: densityState,
|
|
233
|
-
rowSelection,
|
|
234
|
-
columnVisibility,
|
|
235
|
-
},
|
|
236
|
-
onColumnOrderChange: (state) => {
|
|
237
|
-
setColumnOrder(state);
|
|
238
|
-
},
|
|
239
215
|
enableRowSelection: enableRowSelection,
|
|
240
216
|
enableMultiRowSelection: enableMultiRowSelection,
|
|
241
217
|
enableSubRowSelection: enableSubRowSelection,
|
|
@@ -244,17 +220,29 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
244
220
|
filterFns: {
|
|
245
221
|
fuzzy: fuzzyFilter,
|
|
246
222
|
},
|
|
247
|
-
onGlobalFilterChange: setGlobalFilter,
|
|
248
223
|
globalFilterFn: "fuzzy",
|
|
249
|
-
|
|
250
|
-
|
|
224
|
+
state: {
|
|
225
|
+
pagination,
|
|
226
|
+
sorting,
|
|
227
|
+
columnFilters,
|
|
228
|
+
rowSelection,
|
|
229
|
+
columnOrder,
|
|
230
|
+
globalFilter,
|
|
231
|
+
density,
|
|
232
|
+
columnVisibility,
|
|
233
|
+
},
|
|
234
|
+
onPaginationChange: setPagination,
|
|
235
|
+
onSortingChange: setSorting,
|
|
236
|
+
onColumnFiltersChange: setColumnFilters,
|
|
251
237
|
onRowSelectionChange: setRowSelection,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
238
|
+
onColumnOrderChange: (state) => {
|
|
239
|
+
setColumnOrder(state);
|
|
240
|
+
},
|
|
241
|
+
onGlobalFilterChange: (state) => {
|
|
242
|
+
setGlobalFilter(state);
|
|
257
243
|
},
|
|
244
|
+
onDensityChange: setDensity,
|
|
245
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
258
246
|
});
|
|
259
247
|
react$1.useEffect(() => {
|
|
260
248
|
setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
|
|
@@ -308,18 +296,7 @@ const useDataFromUrl = ({ url, params = {}, disableFirstFetch = false, onFetchSu
|
|
|
308
296
|
return { data, loading, hasError, refreshData };
|
|
309
297
|
};
|
|
310
298
|
|
|
311
|
-
const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder
|
|
312
|
-
pageIndex: 0, //initial page index
|
|
313
|
-
pageSize: 10, //default page size
|
|
314
|
-
}, sorting: defaultSorting = [], rowSelection: defaultRowSelection = {}, columnVisibility: defaultColumnVisibility = {}, children, }) => {
|
|
315
|
-
const [sorting, setSorting] = react$1.useState(defaultSorting);
|
|
316
|
-
const [columnFilters, setColumnFilters] = react$1.useState(defaultColumnFilter); // can set initial column filter state here
|
|
317
|
-
const [pagination, setPagination] = react$1.useState(defaultPagination);
|
|
318
|
-
const [rowSelection, setRowSelection] = react$1.useState(defaultRowSelection);
|
|
319
|
-
const [columnOrder, setColumnOrder] = react$1.useState(defaultColumnOrder);
|
|
320
|
-
const [globalFilter, setGlobalFilter] = react$1.useState(defaultGlobalFilter);
|
|
321
|
-
const [densityState, setDensity] = react$1.useState(density);
|
|
322
|
-
const [columnVisibility, setColumnVisibility] = react$1.useState(defaultColumnVisibility);
|
|
299
|
+
const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, children, }) => {
|
|
323
300
|
const { data, loading, hasError, refreshData } = useDataFromUrl({
|
|
324
301
|
url: url,
|
|
325
302
|
defaultData: {
|
|
@@ -341,7 +318,7 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
341
318
|
obj[filter.id] = filter.value;
|
|
342
319
|
return { ...accumulator, ...obj };
|
|
343
320
|
}, {})),
|
|
344
|
-
searching: globalFilter,
|
|
321
|
+
searching: globalFilter.globalFilter,
|
|
345
322
|
},
|
|
346
323
|
disableFirstFetch: true,
|
|
347
324
|
});
|
|
@@ -352,11 +329,15 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
352
329
|
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
353
330
|
manualPagination: true,
|
|
354
331
|
manualSorting: true,
|
|
355
|
-
onPaginationChange: setPagination,
|
|
356
|
-
onSortingChange: setSorting,
|
|
357
|
-
onColumnFiltersChange: setColumnFilters,
|
|
358
332
|
columnResizeMode: "onChange",
|
|
359
|
-
|
|
333
|
+
defaultColumn: {
|
|
334
|
+
size: 150, //starting column size
|
|
335
|
+
minSize: 10, //enforced during column resizing
|
|
336
|
+
maxSize: 10000, //enforced during column resizing
|
|
337
|
+
},
|
|
338
|
+
enableRowSelection: enableRowSelection,
|
|
339
|
+
enableMultiRowSelection: enableMultiRowSelection,
|
|
340
|
+
enableSubRowSelection: enableSubRowSelection,
|
|
360
341
|
state: {
|
|
361
342
|
pagination,
|
|
362
343
|
sorting,
|
|
@@ -364,23 +345,21 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
364
345
|
rowSelection,
|
|
365
346
|
columnOrder,
|
|
366
347
|
globalFilter,
|
|
367
|
-
density
|
|
348
|
+
density,
|
|
368
349
|
columnVisibility,
|
|
369
350
|
},
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
},
|
|
375
|
-
enableRowSelection: enableRowSelection,
|
|
376
|
-
enableMultiRowSelection: enableMultiRowSelection,
|
|
377
|
-
enableSubRowSelection: enableSubRowSelection,
|
|
351
|
+
onPaginationChange: setPagination,
|
|
352
|
+
onSortingChange: setSorting,
|
|
353
|
+
onColumnFiltersChange: setColumnFilters,
|
|
354
|
+
onRowSelectionChange: setRowSelection,
|
|
378
355
|
onColumnOrderChange: (state) => {
|
|
379
356
|
setColumnOrder(state);
|
|
380
357
|
},
|
|
381
358
|
onGlobalFilterChange: (state) => {
|
|
382
359
|
setGlobalFilter(state);
|
|
383
360
|
},
|
|
361
|
+
onDensityChange: setDensity,
|
|
362
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
384
363
|
rowCount: data.count,
|
|
385
364
|
// for tanstack-table ts bug start
|
|
386
365
|
filterFns: {
|
|
@@ -389,8 +368,6 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
389
368
|
},
|
|
390
369
|
},
|
|
391
370
|
// for tanstack-table ts bug end
|
|
392
|
-
onDensityChange: setDensity,
|
|
393
|
-
onColumnVisibilityChange: setColumnVisibility,
|
|
394
371
|
});
|
|
395
372
|
react$1.useEffect(() => {
|
|
396
373
|
refreshData();
|
|
@@ -461,14 +438,14 @@ const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gr
|
|
|
461
438
|
};
|
|
462
439
|
|
|
463
440
|
const TableControls = ({ totalText = "Total:", showFilter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, children = jsxRuntime.jsx(jsxRuntime.Fragment, {}), showFilterName = false, showFilterTags = false, filterOptions = [], }) => {
|
|
464
|
-
const { loading, hasError } =
|
|
441
|
+
const { loading, hasError } = useDataTableContext();
|
|
465
442
|
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto auto auto 1fr auto", templateColumns: "1fr 1fr", width: fitTableWidth ? "fit-content" : "100%", height: fitTableHeight ? "fit-content" : "100%", justifySelf: "center", alignSelf: "center", gap: "0.5rem", children: [jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", gridColumn: "1 / span 2", children: [jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsx(EditViewButton, { text: isMobile ? undefined : "View", icon: jsxRuntime.jsx(md.MdOutlineViewColumn, {}) }) }), jsxRuntime.jsxs(react.Flex, { gap: "1rem", alignItems: "center", justifySelf: "end", children: [loading && jsxRuntime.jsx(react.Spinner, { size: "sm" }), hasError && (jsxRuntime.jsx(react.Tooltip, { label: "An error occurred while fetching data", children: jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsx(react.Icon, { as: bs.BsExclamationCircleFill, color: "red.400" }) }) })), showFilter && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(GlobalFilter, {}), jsxRuntime.jsx(EditFilterButton, { text: isMobile ? undefined : "Advanced Filter" })] }))] })] }), jsxRuntime.jsx(react.Flex, { gridColumn: "1 / span 2", flexFlow: "column", gap: "0.5rem", children: filterOptions.map((column) => {
|
|
466
443
|
return (jsxRuntime.jsxs(react.Flex, { alignItems: "center", flexFlow: "wrap", gap: "0.5rem", children: [showFilterName && jsxRuntime.jsxs(react.Text, { children: [column, ":"] }), jsxRuntime.jsx(FilterOptions, { column: column })] }));
|
|
467
444
|
}) }), jsxRuntime.jsx(react.Flex, { gridColumn: "1 / span 2", children: showFilterTags && jsxRuntime.jsx(TableFilterTags, {}) }), jsxRuntime.jsx(react.Box, { overflow: "auto", gridColumn: "1 / span 2", width: "100%", height: "100%", children: children }), jsxRuntime.jsxs(react.Flex, { gap: "1rem", alignItems: "center", children: [jsxRuntime.jsx(PageSizeControl, {}), jsxRuntime.jsxs(react.Flex, { children: [jsxRuntime.jsx(react.Text, { paddingRight: "0.5rem", children: totalText }), jsxRuntime.jsx(RowCountText, {})] })] }), jsxRuntime.jsx(react.Box, { justifySelf: "end", children: jsxRuntime.jsx(TablePagination, {}) })] }));
|
|
468
445
|
};
|
|
469
446
|
|
|
470
447
|
const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
471
|
-
const table =
|
|
448
|
+
const table = useDataTableContext().table;
|
|
472
449
|
const SELECTION_BOX_WIDTH = 20;
|
|
473
450
|
const [hoveredCheckBox, setHoveredCheckBox] = react$1.useState(false);
|
|
474
451
|
const handleRowHover = (isHovered) => {
|
|
@@ -517,7 +494,7 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }
|
|
|
517
494
|
};
|
|
518
495
|
|
|
519
496
|
const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
520
|
-
const { table } =
|
|
497
|
+
const { table } = useDataTableContext();
|
|
521
498
|
const SELECTION_BOX_WIDTH = 20;
|
|
522
499
|
const [hoveredCheckBox, setHoveredCheckBox] = react$1.useState(false);
|
|
523
500
|
const handleRowHover = (isHovered) => {
|
|
@@ -602,7 +579,7 @@ const DefaultTable = ({ totalText = "Total:", showFilter = false, showFooter = f
|
|
|
602
579
|
};
|
|
603
580
|
|
|
604
581
|
const Table = ({ children, showLoading = false, loadingComponent = jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Loading..." }), ...props }) => {
|
|
605
|
-
const { table, loading } =
|
|
582
|
+
const { table, loading } = useDataTableContext();
|
|
606
583
|
if (showLoading) {
|
|
607
584
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [loading && loadingComponent, !loading && (jsxRuntime.jsx(react.Table, { width: table.getCenterTotalSize(), overflow: "auto", ...props, children: children }))] }));
|
|
608
585
|
}
|
|
@@ -628,7 +605,7 @@ const TableCards = ({ isSelectable = false }) => {
|
|
|
628
605
|
const TableComponent = ({ render = () => {
|
|
629
606
|
throw Error("Not Implemented");
|
|
630
607
|
}, }) => {
|
|
631
|
-
const { table } =
|
|
608
|
+
const { table } = useDataTableContext();
|
|
632
609
|
return render(table);
|
|
633
610
|
};
|
|
634
611
|
|
|
@@ -732,32 +709,32 @@ function Filter({ column }) {
|
|
|
732
709
|
} })] }, column.id));
|
|
733
710
|
}
|
|
734
711
|
const TableFilter = () => {
|
|
735
|
-
const { table } =
|
|
712
|
+
const { table } = useDataTableContext();
|
|
736
713
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getAllColumns().map((column) => {
|
|
737
714
|
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
738
715
|
}) }));
|
|
739
716
|
};
|
|
740
717
|
|
|
741
718
|
const TableFilterTags = () => {
|
|
742
|
-
const { table } =
|
|
743
|
-
return (jsxRuntime.jsx(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }
|
|
719
|
+
const { table } = useDataTableContext();
|
|
720
|
+
return (jsxRuntime.jsx(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }) => {
|
|
744
721
|
return (jsxRuntime.jsxs(react.Tag, { display: "flex", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react.Text, { children: `${id}: ${value}` }), jsxRuntime.jsx(react.IconButton, { size: "xs", variant: "ghost", icon: jsxRuntime.jsx(icons.CloseIcon, {}), onClick: () => {
|
|
745
|
-
table.setColumnFilters(table.getState().columnFilters.filter((
|
|
746
|
-
return
|
|
722
|
+
table.setColumnFilters(table.getState().columnFilters.filter((filter) => {
|
|
723
|
+
return filter.value != value;
|
|
747
724
|
}));
|
|
748
725
|
}, "aria-label": "remove filter" })] }, `${id}-${value}`));
|
|
749
726
|
}) }));
|
|
750
727
|
};
|
|
751
728
|
|
|
752
729
|
const TableLoadingComponent = ({ render, }) => {
|
|
753
|
-
const { loading } =
|
|
730
|
+
const { loading } = useDataTableContext();
|
|
754
731
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(loading) });
|
|
755
732
|
};
|
|
756
733
|
|
|
757
734
|
const ColumnOrderChanger = ({ columns }) => {
|
|
758
735
|
const [order, setOrder] = react$1.useState([]);
|
|
759
736
|
const [originalOrder, setOriginalOrder] = react$1.useState([]);
|
|
760
|
-
const { table } =
|
|
737
|
+
const { table } = useDataTableContext();
|
|
761
738
|
const handleChangeOrder = (startIndex, endIndex) => {
|
|
762
739
|
const newOrder = Array.from(order);
|
|
763
740
|
const [removed] = newOrder.splice(startIndex, 1);
|
|
@@ -803,24 +780,24 @@ const ColumnOrderChanger = ({ columns }) => {
|
|
|
803
780
|
}, children: "Reset" })] })] }));
|
|
804
781
|
};
|
|
805
782
|
const TableOrderer = () => {
|
|
806
|
-
const { table } =
|
|
783
|
+
const { table } = useDataTableContext();
|
|
807
784
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
|
|
808
785
|
};
|
|
809
786
|
|
|
810
787
|
const TablePagination = ({}) => {
|
|
811
|
-
const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } =
|
|
788
|
+
const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } = useDataTableContext().table;
|
|
812
789
|
return (jsxRuntime.jsxs(react.ButtonGroup, { isAttached: true, children: [jsxRuntime.jsx(react.IconButton, { icon: jsxRuntime.jsx(md.MdFirstPage, {}), onClick: () => firstPage(), isDisabled: !getCanPreviousPage(), "aria-label": "first-page", variant: "ghost" }), jsxRuntime.jsx(react.IconButton, { icon: jsxRuntime.jsx(md.MdArrowBack, {}), onClick: () => previousPage(), isDisabled: !getCanPreviousPage(), "aria-label": "previous-page", variant: "ghost" }), jsxRuntime.jsx(react.Button, { variant: "ghost", onClick: () => { }, disabled: !getCanPreviousPage(), children: getState().pagination.pageIndex + 1 }), jsxRuntime.jsx(react.IconButton, { onClick: () => nextPage(), isDisabled: !getCanNextPage(), "aria-label": "next-page", variant: "ghost", children: jsxRuntime.jsx(md.MdArrowForward, {}) }), jsxRuntime.jsx(react.IconButton, { onClick: () => lastPage(), isDisabled: !getCanNextPage(), "aria-label": "last-page", variant: "ghost", children: jsxRuntime.jsx(md.MdLastPage, {}) })] }));
|
|
813
790
|
};
|
|
814
791
|
|
|
815
792
|
const ReloadButton = ({ text = "Reload" }) => {
|
|
816
|
-
const { refreshData } =
|
|
793
|
+
const { refreshData } = useDataTableContext();
|
|
817
794
|
return (jsxRuntime.jsx(react.Button, { leftIcon: jsxRuntime.jsx(io5.IoReload, {}), onClick: () => {
|
|
818
795
|
refreshData();
|
|
819
796
|
}, children: text }));
|
|
820
797
|
};
|
|
821
798
|
|
|
822
|
-
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText, clearAllText, }) => {
|
|
823
|
-
const { table } =
|
|
799
|
+
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText = "", clearAllText = "", }) => {
|
|
800
|
+
const { table } = useDataTableContext();
|
|
824
801
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!selectAllText === false && (jsxRuntime.jsx(react.IconButton, { icon: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, variant: "ghost", "aria-label": table.getIsAllRowsSelected() ? clearAllText : selectAllText, onClick: (event) => {
|
|
825
802
|
table.getToggleAllRowsSelectedHandler()(event);
|
|
826
803
|
} })), !!selectAllText !== false && (jsxRuntime.jsx(react.Button, { leftIcon: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, variant: "ghost", onClick: (event) => {
|
|
@@ -836,11 +813,9 @@ const TableSelector = () => {
|
|
|
836
813
|
};
|
|
837
814
|
|
|
838
815
|
const TableViewer = () => {
|
|
839
|
-
const { table } =
|
|
816
|
+
const { table } = useDataTableContext();
|
|
840
817
|
const columns = table.getAllLeafColumns();
|
|
841
|
-
const [columnOrder, setColumnOrder] = react$1.useState(columns.map(
|
|
842
|
-
return column.id;
|
|
843
|
-
}));
|
|
818
|
+
const [columnOrder, setColumnOrder] = react$1.useState(columns.map(column => column.id));
|
|
844
819
|
const handleDragEnd = (result) => {
|
|
845
820
|
if (!result.destination)
|
|
846
821
|
return;
|
|
@@ -850,12 +825,10 @@ const TableViewer = () => {
|
|
|
850
825
|
setColumnOrder(newColumnOrder);
|
|
851
826
|
table.setColumnOrder(newColumnOrder);
|
|
852
827
|
};
|
|
853
|
-
return (jsxRuntime.jsx(
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
return (jsxRuntime.jsx(reactBeautifulDnd.Draggable, { draggableId: column.id, index: i, children: (provided) => (jsxRuntime.jsxs(react.Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react.Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "auto 0 auto 0", children: jsxRuntime.jsx(react.Icon, { as: fa.FaGripLinesVertical, color: "gray.400" }) }), jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxRuntime.jsxs(react.Box, { children: [" ", displayName] }), jsxRuntime.jsx(react.Switch, { isChecked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] }, column.id)) }, column.id));
|
|
858
|
-
}), provided.placeholder] })) }) }) }));
|
|
828
|
+
return (jsxRuntime.jsx(reactBeautifulDnd.DragDropContext, { onDragEnd: handleDragEnd, children: jsxRuntime.jsx(reactBeautifulDnd.Droppable, { droppableId: "columns", children: (provided) => (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.5rem", ref: provided.innerRef, ...provided.droppableProps, children: [columns.map((column, index) => {
|
|
829
|
+
const displayName = column.columnDef.meta?.displayName || column.id;
|
|
830
|
+
return (jsxRuntime.jsx(reactBeautifulDnd.Draggable, { draggableId: column.id, index: index, children: (provided) => (jsxRuntime.jsxs(react.Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react.Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "0", children: jsxRuntime.jsx(react.Icon, { as: fa.FaGripLinesVertical, color: "gray.400" }) }), jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxRuntime.jsx(react.Box, { children: displayName }), jsxRuntime.jsx(react.Switch, { isChecked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] })) }, column.id));
|
|
831
|
+
}), provided.placeholder] })) }) }));
|
|
859
832
|
};
|
|
860
833
|
|
|
861
834
|
const TextCell = ({ label, noOfLines = [1], padding = "0rem", children, tooltipProps, ...props }) => {
|
|
@@ -865,8 +838,54 @@ const TextCell = ({ label, noOfLines = [1], padding = "0rem", children, tooltipP
|
|
|
865
838
|
return (jsxRuntime.jsx(react.Flex, { alignItems: "center", height: "100%", padding: padding, children: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", noOfLines: noOfLines, ...props, children: children }) }));
|
|
866
839
|
};
|
|
867
840
|
|
|
841
|
+
const useDataTable = ({ default: { sorting: defaultSorting = [], pagination: defaultPagination = {
|
|
842
|
+
pageIndex: 0, //initial page index
|
|
843
|
+
pageSize: 10, //default page size
|
|
844
|
+
}, rowSelection: defaultRowSelection = {}, columnFilters: defaultColumnFilters = [], columnOrder: defaultColumnOrder = [], columnVisibility: defaultColumnVisibility = {}, globalFilter: defaultGlobalFilter = { globalFilter: "" }, density: defaultDensity = "sm", }, } = {
|
|
845
|
+
default: {
|
|
846
|
+
sorting: [],
|
|
847
|
+
pagination: {
|
|
848
|
+
pageIndex: 0, //initial page index
|
|
849
|
+
pageSize: 10, //age size
|
|
850
|
+
},
|
|
851
|
+
rowSelection: {},
|
|
852
|
+
columnFilters: [],
|
|
853
|
+
columnOrder: [],
|
|
854
|
+
columnVisibility: {},
|
|
855
|
+
globalFilter: { globalFilter: "" },
|
|
856
|
+
density: "sm",
|
|
857
|
+
},
|
|
858
|
+
}) => {
|
|
859
|
+
const [sorting, setSorting] = react$1.useState(defaultSorting);
|
|
860
|
+
const [columnFilters, setColumnFilters] = react$1.useState(defaultColumnFilters); // can set initial column filter state here
|
|
861
|
+
const [pagination, setPagination] = react$1.useState(defaultPagination);
|
|
862
|
+
const [rowSelection, setRowSelection] = react$1.useState(defaultRowSelection);
|
|
863
|
+
const [columnOrder, setColumnOrder] = react$1.useState(defaultColumnOrder);
|
|
864
|
+
const [globalFilter, setGlobalFilter] = react$1.useState(defaultGlobalFilter);
|
|
865
|
+
const [density, setDensity] = react$1.useState(defaultDensity);
|
|
866
|
+
const [columnVisibility, setColumnVisibility] = react$1.useState(defaultColumnVisibility);
|
|
867
|
+
return {
|
|
868
|
+
sorting,
|
|
869
|
+
setSorting,
|
|
870
|
+
columnFilters,
|
|
871
|
+
setColumnFilters,
|
|
872
|
+
pagination,
|
|
873
|
+
setPagination,
|
|
874
|
+
rowSelection,
|
|
875
|
+
setRowSelection,
|
|
876
|
+
columnOrder,
|
|
877
|
+
setColumnOrder,
|
|
878
|
+
globalFilter,
|
|
879
|
+
setGlobalFilter,
|
|
880
|
+
density,
|
|
881
|
+
setDensity,
|
|
882
|
+
columnVisibility,
|
|
883
|
+
setColumnVisibility,
|
|
884
|
+
};
|
|
885
|
+
};
|
|
886
|
+
|
|
868
887
|
const FilterOptions = ({ column }) => {
|
|
869
|
-
const { table } =
|
|
888
|
+
const { table } = useDataTableContext();
|
|
870
889
|
const tableColumn = table.getColumn(column);
|
|
871
890
|
const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
|
|
872
891
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
|
|
@@ -886,9 +905,9 @@ const FilterOptions = ({ column }) => {
|
|
|
886
905
|
};
|
|
887
906
|
|
|
888
907
|
const GlobalFilter = ({ icon = md.MdSearch }) => {
|
|
889
|
-
const {
|
|
890
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsxs(react.InputGroup, { children: [jsxRuntime.jsx(react.InputLeftElement, { pointerEvents: "none", children: jsxRuntime.jsx(react.Icon, { as: icon, color: "gray.300" }) }), jsxRuntime.jsx(react.Input, { value: globalFilter, onChange: (e) => {
|
|
891
|
-
setGlobalFilter(e.target.value);
|
|
908
|
+
const { table } = useDataTableContext();
|
|
909
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsxs(react.InputGroup, { children: [jsxRuntime.jsx(react.InputLeftElement, { pointerEvents: "none", children: jsxRuntime.jsx(react.Icon, { as: icon, color: "gray.300" }) }), jsxRuntime.jsx(react.Input, { value: table.getState().globalFilter.globalFilter, onChange: (e) => {
|
|
910
|
+
table.setGlobalFilter(e.target.value);
|
|
892
911
|
} })] }) }) }));
|
|
893
912
|
};
|
|
894
913
|
|
|
@@ -927,3 +946,4 @@ exports.TableViewer = TableViewer;
|
|
|
927
946
|
exports.TextCell = TextCell;
|
|
928
947
|
exports.useDataFromUrl = useDataFromUrl;
|
|
929
948
|
exports.useDataTable = useDataTable;
|
|
949
|
+
exports.useDataTableContext = useDataTableContext;
|