@kayord/ui 2.1.3 → 2.1.4

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 (31) hide show
  1. package/dist/components/custom/data-table/DataTable.svelte +47 -19
  2. package/dist/components/custom/{data-grid/DataGridView.svelte.d.ts → data-table/DataTableView.svelte.d.ts} +3 -3
  3. package/dist/components/custom/data-table/index.d.ts +1 -0
  4. package/dist/components/custom/data-table/index.js +1 -0
  5. package/dist/components/custom/data-table/shad-table-old.svelte.d.ts +9 -0
  6. package/dist/components/custom/data-table/shad-table-old.svelte.js +202 -0
  7. package/dist/components/custom/data-table/shad-table.svelte.js +221 -161
  8. package/dist/components/custom/data-table/types.d.ts +8 -0
  9. package/dist/components/custom/data-table/types.js +7 -1
  10. package/package.json +9 -13
  11. package/dist/components/custom/data-grid/DataGrid.svelte +0 -183
  12. package/dist/components/custom/data-grid/DataGrid.svelte.d.ts +0 -43
  13. package/dist/components/custom/data-grid/DataGridCheckbox.svelte +0 -15
  14. package/dist/components/custom/data-grid/DataGridCheckbox.svelte.d.ts +0 -10
  15. package/dist/components/custom/data-grid/DataGridFooter.svelte +0 -35
  16. package/dist/components/custom/data-grid/DataGridFooter.svelte.d.ts +0 -28
  17. package/dist/components/custom/data-grid/DataGridHeader.svelte +0 -48
  18. package/dist/components/custom/data-grid/DataGridHeader.svelte.d.ts +0 -30
  19. package/dist/components/custom/data-grid/Pagination.svelte +0 -89
  20. package/dist/components/custom/data-grid/Pagination.svelte.d.ts +0 -31
  21. package/dist/components/custom/data-grid/createGrid.svelte.d.ts +0 -3
  22. package/dist/components/custom/data-grid/createGrid.svelte.js +0 -306
  23. package/dist/components/custom/data-grid/index.d.ts +0 -5
  24. package/dist/components/custom/data-grid/index.js +0 -4
  25. package/dist/components/custom/data-grid/types.d.ts +0 -44
  26. package/dist/components/custom/data-grid/types.js +0 -15
  27. package/dist/components/custom/data-table/VisibilitySelect.svelte +0 -27
  28. package/dist/components/custom/data-table/VisibilitySelect.svelte.d.ts +0 -28
  29. package/dist/data-grid/index.d.ts +0 -2
  30. package/dist/data-grid/index.js +0 -2
  31. /package/dist/components/custom/{data-grid/DataGridView.svelte → data-table/DataTableView.svelte} +0 -0
@@ -2,173 +2,103 @@ import { createTable, getCoreRowModel, getFilteredRowModel, getPaginationRowMode
2
2
  import DataTableCheckbox from "./DataTableCheckbox.svelte";
3
3
  import { renderComponent } from "../../../data-table";
4
4
  import { mergeObjects } from "../../ui/data-table/data-table.svelte";
5
+ import { createSubscriber } from "svelte/reactivity";
5
6
  export function createShadTable(shadOptions) {
6
- if (!shadOptions.getCoreRowModel) {
7
- shadOptions.getCoreRowModel = getCoreRowModel();
8
- }
9
- if ((shadOptions.enablePaging ?? true) == false) {
10
- shadOptions.manualPagination = true;
11
- }
12
- if (shadOptions.useURLSearchParams) {
13
- shadOptions.autoResetPageIndex = false;
14
- }
15
- const options = shadOptions;
16
- // Features
17
- // Sorting
18
- if ((options.enableSorting ?? true) && !options.getSortedRowModel) {
19
- options.getSortedRowModel = getSortedRowModel();
20
- if (!options.onSortingChange) {
21
- options.onSortingChange = (updater) => {
22
- if (typeof updater === "function") {
23
- if (options.state?.sorting) {
24
- options.state.sorting = updater(options.state.sorting);
25
- }
26
- else if (state.sorting) {
27
- state.sorting = updater(state.sorting);
28
- }
29
- }
30
- else {
31
- if (options.state?.sorting) {
32
- options.state.sorting = updater;
33
- }
34
- else {
35
- state.sorting = updater;
36
- }
37
- }
38
- };
39
- }
40
- }
41
- // Paging
42
- if ((shadOptions.enablePaging ?? true) && !options.getPaginationRowModel) {
43
- options.getPaginationRowModel = getPaginationRowModel();
44
- if (!options.onPaginationChange) {
45
- options.onPaginationChange = (updater) => {
46
- if (typeof updater === "function") {
47
- if (options.state?.pagination) {
48
- options.state.pagination = updater(options.state.pagination);
49
- }
50
- else if (state.pagination) {
51
- state.pagination = updater(state.pagination);
52
- }
53
- }
54
- else {
55
- if (options.state?.pagination) {
56
- options.state.pagination = updater;
57
- }
58
- else {
59
- state.pagination = updater;
60
- }
61
- }
62
- };
63
- }
64
- }
65
- // Row Selection
66
- if ((options.enableRowSelection ?? true) && !options.onRowSelectionChange) {
67
- options.onRowSelectionChange = (updater) => {
68
- if (typeof updater === "function") {
69
- if (options.state?.rowSelection) {
70
- options.state.rowSelection = updater(options.state.rowSelection);
71
- }
72
- else if (state.rowSelection) {
73
- state.rowSelection = updater(state.rowSelection);
74
- }
7
+ let notifyTableUpdate;
8
+ const subscribeToTable = createSubscriber((update) => {
9
+ notifyTableUpdate = update;
10
+ return () => { };
11
+ });
12
+ const defaultOptions = {
13
+ columns: shadOptions.columns,
14
+ get data() {
15
+ return shadOptions.data;
16
+ },
17
+ getCoreRowModel: getCoreRowModel(),
18
+ getPaginationRowModel: getPaginationRowModel(),
19
+ getSortedRowModel: getSortedRowModel(),
20
+ getFilteredRowModel: getFilteredRowModel(),
21
+ globalFilterFn: "auto",
22
+ columnResizeMode: "onChange",
23
+ // enableColumnResizing: true
24
+ enableRowSelection: false,
25
+ // enableFilters: true,
26
+ enableGlobalFilter: true,
27
+ onSortingChange: (updater) => {
28
+ if (options.state?.sorting) {
29
+ options.state.sorting = typeof updater === "function" ? updater(options.state.sorting) : updater;
75
30
  }
76
- else {
77
- if (options.state?.rowSelection) {
78
- options.state.rowSelection = updater;
79
- }
80
- else {
81
- state.rowSelection = updater;
82
- }
31
+ else if (state.sorting) {
32
+ state.sorting = typeof updater === "function" ? updater(state.sorting) : updater;
83
33
  }
84
- };
85
- }
86
- if (options.enableRowSelection && (shadOptions.enableRowSelectionUI ?? true)) {
87
- const rowSelectionColumn = {
88
- id: "select",
89
- header: () => renderComponent(DataTableCheckbox, {
90
- checked: table.getIsAllPageRowsSelected(),
91
- onCheckedChange: () => table.toggleAllPageRowsSelected(),
92
- }),
93
- cell: (r) => renderComponent(DataTableCheckbox, {
94
- checked: r.row.getIsSelected(),
95
- onCheckedChange: () => r.row.toggleSelected(),
96
- }),
97
- enableResizing: false,
98
- enableSorting: false,
99
- };
100
- options.columns.unshift(rowSelectionColumn);
101
- }
102
- // Column Visibility
103
- if ((shadOptions.enableVisibility ?? false) && !options.onColumnVisibilityChange) {
104
- options.onColumnVisibilityChange = (updater) => {
105
- if (typeof updater === "function") {
106
- if (options.state?.columnVisibility) {
107
- options.state.columnVisibility = updater(options.state.columnVisibility);
108
- }
109
- else if (state.columnVisibility) {
110
- state.columnVisibility = updater(state.columnVisibility);
111
- }
34
+ notifyTableUpdate?.();
35
+ },
36
+ // onColumnSizingChange: (updater) => {
37
+ // columnSizing = typeof updater === "function" ? updater(columnSizing) : updater;
38
+ // },
39
+ // onColumnSizingInfoChange: (updater) => {
40
+ // columnSizingInfo = typeof updater === "function" ? updater(columnSizingInfo) : updater;
41
+ // },
42
+ // onColumnPinningChange: (updater) => {
43
+ // columnPinning = typeof updater === "function" ? updater(columnPinning) : updater;
44
+ // },
45
+ onColumnVisibilityChange: (updater) => {
46
+ if (options.state?.columnVisibility) {
47
+ options.state.columnVisibility =
48
+ typeof updater === "function" ? updater(options.state.columnVisibility) : updater;
112
49
  }
113
- else {
114
- if (options.state?.columnVisibility) {
115
- options.state.columnVisibility = updater;
116
- }
117
- else {
118
- state.columnVisibility = updater;
119
- }
50
+ else if (state.columnVisibility) {
51
+ state.columnVisibility = typeof updater === "function" ? updater(state.columnVisibility) : updater;
120
52
  }
121
- };
122
- }
123
- // Filtering
124
- if ((options.enableFilters ?? true) && !options.getFilteredRowModel) {
125
- options.getFilteredRowModel = getFilteredRowModel();
126
- // Global Filtering
127
- if (options.enableGlobalFilter ?? false) {
128
- if (!options.onGlobalFilterChange) {
129
- options.onGlobalFilterChange = (updater) => {
130
- if (typeof updater === "function") {
131
- if (options.state?.globalFilter) {
132
- options.state.globalFilter = updater(options.state.globalFilter);
133
- }
134
- else if (state.globalFilter) {
135
- state.globalFilter = updater(state.globalFilter);
136
- }
137
- }
138
- else {
139
- if (options.state?.globalFilter) {
140
- options.state.globalFilter = updater;
141
- }
142
- else {
143
- state.globalFilter = updater;
144
- }
145
- }
146
- };
53
+ notifyTableUpdate?.();
54
+ },
55
+ onPaginationChange: (updater) => {
56
+ if (options.state?.pagination) {
57
+ options.state.pagination = typeof updater === "function" ? updater(options.state.pagination) : updater;
58
+ }
59
+ else if (state.pagination) {
60
+ state.pagination = typeof updater === "function" ? updater(state.pagination) : updater;
147
61
  }
148
- }
149
- else {
150
- if (!options.onColumnFiltersChange) {
151
- options.onColumnFiltersChange = (updater) => {
152
- if (typeof updater === "function") {
153
- if (options.state?.columnFilters) {
154
- options.state.columnFilters = updater(options.state.columnFilters);
155
- }
156
- else if (state.columnFilters) {
157
- state.columnFilters = updater(state.columnFilters);
158
- }
159
- }
160
- else {
161
- if (options.state?.columnFilters) {
162
- options.state.columnFilters = updater;
163
- }
164
- else {
165
- state.columnFilters = updater;
166
- }
167
- }
168
- };
62
+ notifyTableUpdate?.();
63
+ },
64
+ onColumnFiltersChange: (updater) => {
65
+ if (options.state?.columnFilters) {
66
+ options.state.columnFilters = typeof updater === "function" ? updater(options.state.columnFilters) : updater;
67
+ }
68
+ else if (state.columnFilters) {
69
+ state.columnFilters = typeof updater === "function" ? updater(state.columnFilters) : updater;
70
+ }
71
+ notifyTableUpdate?.();
72
+ },
73
+ onRowSelectionChange: (updater) => {
74
+ if (options.state?.rowSelection) {
75
+ options.state.rowSelection = typeof updater === "function" ? updater(options.state.rowSelection) : updater;
76
+ }
77
+ else if (state.rowSelection) {
78
+ state.rowSelection = typeof updater === "function" ? updater(state.rowSelection) : updater;
79
+ }
80
+ notifyTableUpdate?.();
81
+ },
82
+ onGlobalFilterChange: (updater) => {
83
+ if (options.state?.globalFilter) {
84
+ options.state.globalFilter = typeof updater === "function" ? updater(options.state.globalFilter) : updater;
85
+ }
86
+ else {
87
+ state.globalFilter = typeof updater === "function" ? updater(state.globalFilter) : updater;
169
88
  }
170
- }
89
+ notifyTableUpdate?.();
90
+ },
91
+ };
92
+ if (shadOptions.useURLSearchParams) {
93
+ shadOptions.autoResetPageIndex = false;
94
+ }
95
+ if ((shadOptions.enablePaging ?? true) == false) {
96
+ defaultOptions.getPaginationRowModel = undefined;
97
+ defaultOptions.manualPagination = true;
171
98
  }
99
+ // Use default but extend with shadOptions, excluding data to preserve reactivity.
100
+ // Using mergeObjects to keep getter in tact
101
+ const options = mergeObjects(defaultOptions, shadOptions ?? {});
172
102
  const resolvedOptions = mergeObjects({
173
103
  state: {},
174
104
  onStateChange() { },
@@ -178,7 +108,31 @@ export function createShadTable(shadOptions) {
178
108
  },
179
109
  }, options);
180
110
  const table = createTable(resolvedOptions);
181
- let state = $state(table.initialState);
111
+ const state = $state(table.initialState);
112
+ // Row Selection
113
+ if (options.enableRowSelection && (shadOptions.enableRowSelectionUI ?? true)) {
114
+ const rowSelectionColumn = {
115
+ id: "select",
116
+ header: () => {
117
+ subscribeToTable();
118
+ return renderComponent(DataTableCheckbox, {
119
+ checked: table.getIsAllPageRowsSelected(),
120
+ indeterminate: table.getIsSomePageRowsSelected(),
121
+ onCheckedChange: () => table.toggleAllPageRowsSelected(),
122
+ });
123
+ },
124
+ cell: (r) => {
125
+ subscribeToTable();
126
+ return renderComponent(DataTableCheckbox, {
127
+ checked: r.row.getIsSelected(),
128
+ onCheckedChange: () => r.row.toggleSelected(),
129
+ });
130
+ },
131
+ enableResizing: false,
132
+ enableSorting: false,
133
+ };
134
+ options.columns.unshift(rowSelectionColumn);
135
+ }
182
136
  const updateOptions = (table, state) => {
183
137
  table.setOptions((prev) => {
184
138
  return mergeObjects(prev, options, {
@@ -198,5 +152,111 @@ export function createShadTable(shadOptions) {
198
152
  $effect.pre(() => {
199
153
  updateOptions(table, state);
200
154
  });
201
- return table;
155
+ const reactiveTable = {
156
+ // Expose all original table methods and properties
157
+ ...table,
158
+ // Override methods that depend on state to create reactive dependencies
159
+ getRowModel: () => {
160
+ subscribeToTable();
161
+ return table.getRowModel();
162
+ },
163
+ getHeaderGroups: () => {
164
+ subscribeToTable();
165
+ return table.getHeaderGroups();
166
+ },
167
+ getAllColumns: () => {
168
+ subscribeToTable();
169
+ return table.getAllColumns();
170
+ },
171
+ getVisibleLeafColumns: () => {
172
+ subscribeToTable();
173
+ return table.getVisibleLeafColumns();
174
+ },
175
+ getState: () => {
176
+ subscribeToTable();
177
+ return table.getState();
178
+ },
179
+ getPageCount: () => {
180
+ subscribeToTable();
181
+ return table.getPageCount();
182
+ },
183
+ getColumn: (columnId) => {
184
+ subscribeToTable();
185
+ return table.getColumn(columnId);
186
+ },
187
+ // Forward all other methods to the original table
188
+ setColumnFilters: table.setColumnFilters.bind(table),
189
+ setSorting: table.setSorting.bind(table),
190
+ setPagination: table.setPagination.bind(table),
191
+ setPageIndex: table.setPageIndex.bind(table),
192
+ setPageSize: table.setPageSize.bind(table),
193
+ setColumnPinning: table.setColumnPinning.bind(table),
194
+ setColumnVisibility: table.setColumnVisibility.bind(table),
195
+ setRowSelection: table.setRowSelection.bind(table),
196
+ setColumnSizing: table.setColumnSizing.bind(table),
197
+ setOptions: table.setOptions.bind(table),
198
+ setGlobalFilter: table.setGlobalFilter.bind(table),
199
+ getFlatHeaders: () => {
200
+ subscribeToTable();
201
+ return table.getFlatHeaders();
202
+ },
203
+ getTotalSize: () => {
204
+ subscribeToTable();
205
+ return table.getTotalSize();
206
+ },
207
+ getLeftLeafColumns: () => {
208
+ subscribeToTable();
209
+ return table.getLeftLeafColumns();
210
+ },
211
+ getRowCount: () => {
212
+ subscribeToTable();
213
+ return table.getRowCount();
214
+ },
215
+ getRightLeafColumns: () => {
216
+ subscribeToTable();
217
+ return table.getRightLeafColumns();
218
+ },
219
+ getCenterLeafColumns: () => {
220
+ subscribeToTable();
221
+ return table.getCenterLeafColumns();
222
+ },
223
+ getIsAllRowsSelected: () => {
224
+ subscribeToTable();
225
+ return table.getIsAllRowsSelected();
226
+ },
227
+ getIsSomeRowsSelected: () => {
228
+ subscribeToTable();
229
+ return table.getIsSomeRowsSelected();
230
+ },
231
+ getIsAllPageRowsSelected: () => {
232
+ subscribeToTable();
233
+ return table.getIsAllPageRowsSelected();
234
+ },
235
+ getIsSomePageRowsSelected: () => {
236
+ subscribeToTable();
237
+ return table.getIsSomePageRowsSelected();
238
+ },
239
+ getCanPreviousPage: () => {
240
+ subscribeToTable();
241
+ return table.getCanPreviousPage();
242
+ },
243
+ getCanNextPage: () => {
244
+ subscribeToTable();
245
+ return table.getCanNextPage();
246
+ },
247
+ getFilteredSelectedRowModel: () => {
248
+ subscribeToTable();
249
+ return table.getFilteredSelectedRowModel();
250
+ },
251
+ toggleAllRowsSelected: table.toggleAllRowsSelected.bind(table),
252
+ toggleAllPageRowsSelected: table.toggleAllPageRowsSelected.bind(table),
253
+ // Keep table reference for any other property access
254
+ _getDefaultColumnDef: table._getDefaultColumnDef.bind(table),
255
+ get options() {
256
+ subscribeToTable();
257
+ return table.options;
258
+ },
259
+ initialState: table.initialState,
260
+ };
261
+ return reactiveTable;
202
262
  }
@@ -1,6 +1,14 @@
1
+ import z from "zod";
1
2
  export interface CustomOptions {
2
3
  useURLSearchParams?: boolean;
3
4
  }
4
5
  export interface CustomColumnMeta {
5
6
  className?: string;
6
7
  }
8
+ export declare const defaultSearchParamSchema: z.ZodObject<{
9
+ search: z.ZodDefault<z.ZodAny>;
10
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
11
+ filter: z.ZodDefault<z.ZodString>;
12
+ sort: z.ZodDefault<z.ZodString>;
13
+ }, z.core.$strip>;
14
+ export type SearchParamSchema = z.infer<typeof defaultSearchParamSchema>;
@@ -1 +1,7 @@
1
- export {};
1
+ import z from "zod";
2
+ export const defaultSearchParamSchema = z.object({
3
+ search: z.any().default(""),
4
+ page: z.coerce.number().default(0),
5
+ filter: z.string().default(""),
6
+ sort: z.string().default(""),
7
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "2.1.3",
4
+ "version": "2.1.4",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -23,10 +23,6 @@
23
23
  "types": "./dist/data-table/index.d.ts",
24
24
  "default": "./dist/data-table/index.js"
25
25
  },
26
- "./data-grid": {
27
- "types": "./dist/data-grid/index.d.ts",
28
- "default": "./dist/data-grid/index.js"
29
- },
30
26
  "./drawer": {
31
27
  "types": "./dist/drawer/index.d.ts",
32
28
  "default": "./dist/drawer/index.js"
@@ -122,8 +118,8 @@
122
118
  "@tailwindcss/vite": "^4.1.18",
123
119
  "@types/d3-scale": "^4.0.9",
124
120
  "@types/d3-shape": "^3.1.8",
125
- "@vitest/browser": "^4.0.17",
126
- "@vitest/browser-playwright": "^4.0.17",
121
+ "@vitest/browser": "^4.0.18",
122
+ "@vitest/browser-playwright": "^4.0.18",
127
123
  "d3-scale": "^4.0.2",
128
124
  "d3-shape": "^3.2.0",
129
125
  "embla-carousel-svelte": "^8.6.0",
@@ -135,12 +131,12 @@
135
131
  "layerchart": "2.0.0-next.40",
136
132
  "mode-watcher": "^1.1.0",
137
133
  "paneforge": "^1.0.2",
138
- "prettier": "^3.8.0",
134
+ "prettier": "^3.8.1",
139
135
  "prettier-plugin-svelte": "^3.4.1",
140
136
  "prettier-plugin-tailwindcss": "^0.7.2",
141
- "publint": "^0.3.16",
137
+ "publint": "^0.3.17",
142
138
  "runed": "^0.37.1",
143
- "svelte": "5.47.1",
139
+ "svelte": "5.48.0",
144
140
  "svelte-check": "^4.3.5",
145
141
  "svelte-sonner": "^1.0.7",
146
142
  "sveltekit-superforms": "^2.29.1",
@@ -151,9 +147,9 @@
151
147
  "typescript-eslint": "^8.53.1",
152
148
  "vaul-svelte": "1.0.0-next.7",
153
149
  "vite": "^7.3.1",
154
- "vitest": "^4.0.17",
155
- "vitest-browser-svelte": "^2.0.0",
156
- "zod": "4.3.5"
150
+ "vitest": "^4.0.18",
151
+ "vitest-browser-svelte": "^2.0.2",
152
+ "zod": "4.3.6"
157
153
  },
158
154
  "svelte": "./dist/index.js",
159
155
  "types": "./dist/index.d.ts",
@@ -1,183 +0,0 @@
1
- <script lang="ts" generics="T">
2
- import { type Table as TableType } from "@tanstack/table-core";
3
- import { FlexRender } from "../../ui/data-table";
4
- import { Skeleton, Table } from "../../ui";
5
- import Pagination from "./Pagination.svelte";
6
- import { onMount, type Snippet } from "svelte";
7
- import { fade } from "svelte/transition";
8
- import { ProgressLoading } from "../progress-loading";
9
- import { cn } from "../../../utils";
10
- import DataGridHeader from "./DataGridHeader.svelte";
11
- import DataGridFooter from "./DataGridFooter.svelte";
12
- import { defaultDataGridProps, defaultSearchParamSchema, type DataGridProps } from "./types";
13
- import DataGridView from "./DataGridView.svelte";
14
- import { useSearchParams } from "runed/kit";
15
- import { untrack } from "svelte";
16
- import { decodeColumnFilters, decodeSorting, encodeColumnFilters, encodeSorting } from "../data-table";
17
-
18
- interface Props<T> {
19
- table: TableType<T>;
20
- dataGridProps?: DataGridProps;
21
- isLoading?: boolean;
22
- header?: Snippet;
23
- subHeader?: Snippet;
24
- footer?: Snippet;
25
- leftToolbar?: Snippet;
26
- rightToolbar?: Snippet;
27
- noDataMessage?: string;
28
- hideHeader?: boolean;
29
- enableVisibility?: boolean;
30
- class?: string;
31
- headerClass?: string;
32
- disableUISorting?: boolean;
33
- }
34
-
35
- let {
36
- table,
37
- dataGridProps = defaultDataGridProps,
38
- isLoading = false,
39
- header,
40
- subHeader,
41
- footer,
42
- leftToolbar,
43
- rightToolbar,
44
- noDataMessage = "No data",
45
- hideHeader = false,
46
- enableVisibility = false,
47
- class: className,
48
- headerClass,
49
- disableUISorting = false,
50
- }: Props<T> = $props();
51
-
52
- let end: HTMLElement | undefined = $state();
53
-
54
- const tableState = $derived(table.getState());
55
- const columnVisibility = $derived(tableState.columnVisibility);
56
-
57
- const params = useSearchParams(defaultSearchParamSchema, { pushHistory: false });
58
-
59
- // Load current url search params
60
- onMount(() => {
61
- if (dataGridProps.useURLSearchParams) {
62
- table.setGlobalFilter(params.search);
63
- table.setSorting(decodeSorting() ?? []);
64
- table.setPageIndex(params.page);
65
- table.setColumnFilters(decodeColumnFilters() ?? []);
66
- }
67
- });
68
-
69
- // Set url search params
70
- $effect(() => {
71
- if (dataGridProps.useURLSearchParams) {
72
- const tableState = table.getState();
73
- untrack(() => {
74
- params.search = tableState.globalFilter;
75
- params.page = tableState.pagination.pageIndex;
76
- params.sort = encodeSorting(tableState);
77
- params.filter = encodeColumnFilters(tableState);
78
- });
79
- }
80
- });
81
- </script>
82
-
83
- <div class={cn("w-full", className)}>
84
- <div class={cn(headerClass)}>
85
- {#if header}
86
- {@render header()}
87
- {:else}
88
- <div class="flex items-center justify-between gap-2 pb-2">
89
- <div>
90
- {#if leftToolbar}
91
- {@render leftToolbar()}
92
- {/if}
93
- </div>
94
- <div></div>
95
- <div class="flex items-center justify-between gap-2">
96
- {#if rightToolbar}
97
- {@render rightToolbar()}
98
- {/if}
99
- {#if enableVisibility}
100
- <DataGridView {table} />
101
- {/if}
102
- </div>
103
- </div>
104
- {/if}
105
- </div>
106
-
107
- <div class="rounded-md border">
108
- {#if isLoading}
109
- <span in:fade={{ duration: 300 }}>
110
- <ProgressLoading class="h-1" />
111
- </span>
112
- {/if}
113
-
114
- {#if subHeader}
115
- {@render subHeader()}
116
- {/if}
117
-
118
- <Table.Root class="table-auto">
119
- {#if !hideHeader}
120
- <Table.Header>
121
- {#each table.getHeaderGroups() as headerGroup (headerGroup.id)}
122
- <Table.Row>
123
- {#each headerGroup.headers.filter((h) => columnVisibility[h.column.id] !== false) as header (header.id)}
124
- <DataGridHeader {header} {table} {disableUISorting} />
125
- {/each}
126
- </Table.Row>
127
- {/each}
128
- </Table.Header>
129
- {/if}
130
-
131
- <Table.Body>
132
- {#if isLoading && table.getRowModel().rows.length == 0}
133
- {#each { length: 5 }}
134
- <Table.Row>
135
- {#each table.getAllColumns() as _cell (_cell.id)}
136
- <Table.Cell>
137
- <Skeleton class="h-4" />
138
- </Table.Cell>
139
- {/each}
140
- </Table.Row>
141
- {/each}
142
- {:else}
143
- {#if table.getRowModel().rows.length == 0}
144
- <Table.Row>
145
- <Table.Cell colspan={table.getAllColumns().length}>
146
- <div class="text-center">{noDataMessage}</div>
147
- </Table.Cell>
148
- </Table.Row>
149
- {/if}
150
- {#each table.getRowModel().rows as row (row.id)}
151
- <Table.Row data-state={row.getIsSelected() && "selected"}>
152
- {#each row.getVisibleCells() as cell (cell.id)}
153
- <Table.Cell
154
- class={cell.column.columnDef.meta?.className}
155
- style={`width: ${cell.column.getSize()}px; min-width:${cell.column.columnDef.minSize}px; max-width:${cell.column.columnDef.maxSize}px`}
156
- >
157
- <FlexRender content={cell.column.columnDef.cell} context={cell.getContext()} />
158
- </Table.Cell>
159
- {/each}
160
- </Table.Row>
161
- {/each}
162
- {/if}
163
- </Table.Body>
164
- <DataGridFooter {table} />
165
- </Table.Root>
166
- {#if isLoading}
167
- <span in:fade={{ duration: 300 }}>
168
- <ProgressLoading class="h-1" />
169
- </span>
170
- {/if}
171
- </div>
172
- {#if dataGridProps.isPaginationEnabled}
173
- <Pagination {table} {dataGridProps} />
174
- {/if}
175
-
176
- {#if footer}
177
- <div class="overflow-hidden rounded-b-md">
178
- {@render footer()}
179
- </div>
180
- {/if}
181
- </div>
182
-
183
- <div bind:this={end} aria-hidden="true"></div>