@bsol-oss/react-datatable5 1.0.64 → 2.0.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.
Files changed (51) hide show
  1. package/dist/index.d.ts +40 -31
  2. package/dist/index.js +77 -104
  3. package/dist/index.mjs +78 -105
  4. package/dist/types/components/Controls/SelectAllRowsToggle.d.ts +4 -4
  5. package/dist/types/components/DataTable/DataTable.d.ts +18 -13
  6. package/dist/types/components/DataTable/DataTableContext.d.ts +3 -3
  7. package/dist/types/components/DataTable/DataTableServer.d.ts +18 -14
  8. package/dist/types/components/DataTable/useDataTable.d.ts +33 -8
  9. package/dist/types/components/DataTable/useDataTableContext.d.ts +8 -0
  10. package/dist/types/index.d.ts +1 -1
  11. package/package.json +1 -1
  12. package/dist/types/components/DataTable.d.ts +0 -33
  13. package/dist/types/components/DataTableContext.d.ts +0 -10
  14. package/dist/types/components/DataTableServer.d.ts +0 -38
  15. package/dist/types/components/DefaultTable.d.ts +0 -5
  16. package/dist/types/components/DensityFeature.d.ts +0 -23
  17. package/dist/types/components/DensityToggle.d.ts +0 -1
  18. package/dist/types/components/DensityToggleButton.d.ts +0 -6
  19. package/dist/types/components/EditFilterButton.d.ts +0 -9
  20. package/dist/types/components/EditOrderButton.d.ts +0 -7
  21. package/dist/types/components/EditSortingButton.d.ts +0 -7
  22. package/dist/types/components/EditViewButton.d.ts +0 -7
  23. package/dist/types/components/FilterOptions.d.ts +0 -4
  24. package/dist/types/components/GlobalFilter.d.ts +0 -3
  25. package/dist/types/components/PageSizeControl.d.ts +0 -4
  26. package/dist/types/components/ResetFilteringButton.d.ts +0 -4
  27. package/dist/types/components/ResetSelectionButton.d.ts +0 -4
  28. package/dist/types/components/ResetSortingButton.d.ts +0 -4
  29. package/dist/types/components/RowCountText.d.ts +0 -1
  30. package/dist/types/components/SelectAllRowsToggle.d.ts +0 -8
  31. package/dist/types/components/Table.d.ts +0 -8
  32. package/dist/types/components/TableBody.d.ts +0 -17
  33. package/dist/types/components/TableCardContainer.d.ts +0 -6
  34. package/dist/types/components/TableCards.d.ts +0 -4
  35. package/dist/types/components/TableComponent.d.ts +0 -6
  36. package/dist/types/components/TableComponentRenderer.d.ts +0 -6
  37. package/dist/types/components/TableControls.d.ts +0 -13
  38. package/dist/types/components/TableFilter.d.ts +0 -8
  39. package/dist/types/components/TableFilterTags.d.ts +0 -1
  40. package/dist/types/components/TableFooter.d.ts +0 -7
  41. package/dist/types/components/TableHeader.d.ts +0 -8
  42. package/dist/types/components/TableLoadingComponent.d.ts +0 -5
  43. package/dist/types/components/TableOrderer.d.ts +0 -1
  44. package/dist/types/components/TablePagination.d.ts +0 -3
  45. package/dist/types/components/TableReloadButton.d.ts +0 -4
  46. package/dist/types/components/TableSelector.d.ts +0 -1
  47. package/dist/types/components/TableSorter.d.ts +0 -1
  48. package/dist/types/components/TableViewer.d.ts +0 -1
  49. package/dist/types/components/TextCell.d.ts +0 -10
  50. package/dist/types/components/useDataFromUrl.d.ts +0 -14
  51. 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?: string[];
107
- columnFilters?: ColumnFiltersState;
108
- globalFilter?: string;
109
- density?: DensityState;
110
- pagination?: {
111
- pageIndex: number;
112
- pageSize: number;
113
- };
114
- sorting?: SortingState;
115
- rowSelection?: RowSelectionState;
116
- columnVisibility?: VisibilityState;
117
- }
118
- declare const DataTable: <TData>({ columns, data, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, onRowSelect, columnOrder: defaultColumnOrder, columnFilters: defaultColumnFilter, density, globalFilter: defaultGlobalFilter, pagination: defaultPagination, sorting: defaultSorting, rowSelection: defaultRowSelection, columnVisibility: defaultColumnVisibility, children, }: DataTableProps<TData>) => react_jsx_runtime.JSX.Element;
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?: string[];
129
- columnFilters?: ColumnFiltersState;
130
- globalFilter?: string;
131
- density?: DensityState;
132
- pagination?: {
133
- pageIndex: number;
134
- pageSize: number;
135
- };
136
- sorting?: SortingState;
137
- rowSelection?: RowSelectionState;
138
- loadingComponent?: JSX.Element;
139
- columnVisibility?: VisibilityState;
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: defaultColumnOrder, columnFilters: defaultColumnFilter, density, globalFilter: defaultGlobalFilter, pagination: defaultPagination, sorting: defaultSorting, rowSelection: defaultRowSelection, columnVisibility: defaultColumnVisibility, children, }: DataTableServerProps<TData>) => react_jsx_runtime.JSX.Element;
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,11 @@ interface useDataFromUrlProps<T> {
272
281
  }
273
282
  declare const useDataFromUrl: <T>({ url, params, disableFirstFetch, onFetchSuccess, defaultData, }: useDataFromUrlProps<T>) => useDataFromUrlReturn<T>;
274
283
 
275
- declare const useDataTable: () => {
284
+ declare const useDataTableContext: () => {
276
285
  table: _tanstack_table_core.Table<any>;
277
286
  refreshData: () => void;
278
- globalFilter: string;
279
- setGlobalFilter: (filter: string) => void;
287
+ globalFilter: _tanstack_table_core.GlobalFilterTableState;
288
+ setGlobalFilter: _tanstack_table_core.OnChangeFn<_tanstack_table_core.GlobalFilterTableState>;
280
289
  loading: boolean;
281
290
  hasError: boolean;
282
291
  };
@@ -342,4 +351,4 @@ declare module "@tanstack/react-table" {
342
351
  }
343
352
  }
344
353
 
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 };
354
+ 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, 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 } = useDataTable();
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 useDataTable = () => {
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 } = useDataTable();
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: (e) => {
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 } = useDataTable();
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 } = useDataTable();
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 } = useDataTable();
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 } = useDataTable();
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 } = useDataTable();
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: defaultColumnOrder = [], columnFilters: defaultColumnFilter = [], density = "sm", globalFilter: defaultGlobalFilter = "", pagination: defaultPagination = {
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
- // global filter end
250
- onDensityChange: setDensity,
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
- onColumnVisibilityChange: setColumnVisibility,
253
- initialState: {
254
- columnFilters: defaultColumnFilter,
255
- sorting: defaultSorting,
256
- pagination: defaultPagination,
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: defaultColumnOrder = [], columnFilters: defaultColumnFilter = [], density = "sm", globalFilter: defaultGlobalFilter = "", pagination: defaultPagination = {
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
- onRowSelectionChange: setRowSelection,
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: densityState,
348
+ density,
368
349
  columnVisibility,
369
350
  },
370
- defaultColumn: {
371
- size: 150, //starting column size
372
- minSize: 10, //enforced during column resizing
373
- maxSize: 10000, //enforced during column resizing
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 } = useDataTable();
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 = useDataTable().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 } = useDataTable();
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 } = useDataTable();
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 } = useDataTable();
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 } = useDataTable();
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 } = useDataTable();
743
- return (jsxRuntime.jsx(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }, index) => {
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((value, curIndex) => {
746
- return curIndex != index;
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 } = useDataTable();
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 } = useDataTable();
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 } = useDataTable();
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, } = useDataTable().table;
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 } = useDataTable();
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 } = useDataTable();
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 } = useDataTable();
816
+ const { table } = useDataTableContext();
840
817
  const columns = table.getAllLeafColumns();
841
- const [columnOrder, setColumnOrder] = react$1.useState(columns.map((column, index) => {
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(jsxRuntime.Fragment, { children: 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, i) => {
854
- const displayName = column.columnDef.meta === undefined
855
- ? column.id
856
- : column.columnDef.meta.displayName;
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 }) => {
@@ -866,7 +839,7 @@ const TextCell = ({ label, noOfLines = [1], padding = "0rem", children, tooltipP
866
839
  };
867
840
 
868
841
  const FilterOptions = ({ column }) => {
869
- const { table } = useDataTable();
842
+ const { table } = useDataTableContext();
870
843
  const tableColumn = table.getColumn(column);
871
844
  const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
872
845
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
@@ -886,9 +859,9 @@ const FilterOptions = ({ column }) => {
886
859
  };
887
860
 
888
861
  const GlobalFilter = ({ icon = md.MdSearch }) => {
889
- const { globalFilter, setGlobalFilter } = useDataTable();
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);
862
+ const { table } = useDataTableContext();
863
+ 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) => {
864
+ table.setGlobalFilter(e.target.value);
892
865
  } })] }) }) }));
893
866
  };
894
867
 
@@ -926,4 +899,4 @@ exports.TableSorter = TableSorter;
926
899
  exports.TableViewer = TableViewer;
927
900
  exports.TextCell = TextCell;
928
901
  exports.useDataFromUrl = useDataFromUrl;
929
- exports.useDataTable = useDataTable;
902
+ exports.useDataTableContext = useDataTableContext;