@timlassiter11/yatl 0.3.2 → 0.3.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.
- package/README.md +8 -5
- package/dist/data-table.css +2 -0
- package/dist/data-table.css.map +1 -0
- package/dist/{datatable.d.mts → data-table.d.mts} +189 -109
- package/dist/{datatable.d.ts → data-table.d.ts} +189 -109
- package/dist/data-table.global.js +4 -0
- package/dist/data-table.global.js.map +1 -0
- package/dist/data-table.js +4 -0
- package/dist/data-table.js.map +1 -0
- package/dist/data-table.mjs +4 -0
- package/dist/data-table.mjs.map +1 -0
- package/package.json +10 -10
- package/dist/datatable.css +0 -2
- package/dist/datatable.css.map +0 -1
- package/dist/datatable.global.js +0 -4
- package/dist/datatable.global.js.map +0 -1
- package/dist/datatable.js +0 -4
- package/dist/datatable.js.map +0 -1
- package/dist/datatable.mjs +0 -4
- package/dist/datatable.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -35,16 +35,16 @@ const datatble = DataTable("#myTable", {
|
|
|
35
35
|
|
|
36
36
|
### source (ES6)
|
|
37
37
|
```javascript
|
|
38
|
-
import { DataTable } from "path/to/
|
|
38
|
+
import { DataTable } from "path/to/data-table.esm.js";
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const dataTable = new DataTable("#myTable", {
|
|
41
41
|
...
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
### source (UMD)
|
|
46
46
|
```html
|
|
47
|
-
<script src="path/to/
|
|
47
|
+
<script src="path/to/data-table.umd.js"></script>
|
|
48
48
|
<script>
|
|
49
49
|
const datatble = new yatl.DataTable("#myTable", {
|
|
50
50
|
...
|
|
@@ -57,12 +57,12 @@ Some optional styling is included which adds sorting indicators and sticky heade
|
|
|
57
57
|
|
|
58
58
|
### npm
|
|
59
59
|
```ts
|
|
60
|
-
import "@timlassiter11/yatl/
|
|
60
|
+
import "@timlassiter11/yatl/data-table.css";
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
### source
|
|
64
64
|
```html
|
|
65
|
-
<link rel="stylesheet" href="path/to/
|
|
65
|
+
<link rel="stylesheet" href="path/to/data-table.css">
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
## Usage
|
|
@@ -134,6 +134,9 @@ Most of the time this isn't ideal though and instead we'd like to let the layout
|
|
|
134
134
|
|
|
135
135
|
Since the `dt-scroller` wrapper listens to scroll and resize events, this allows the table to be responsive and update what is rendered as the layout changes.
|
|
136
136
|
|
|
137
|
+
### Docs
|
|
138
|
+
Full API docs can be found [here](https://timlassiter11.github.io/YATL/docs/index.html).
|
|
139
|
+
|
|
137
140
|
# Known Issues
|
|
138
141
|
There are some limitations to virtual scrolling. For one, rows need to be a uniform height to accurately calculate the table height. Also, there seems to be a maximum element size that once exceeded, the contents are no longer rendered. I've found this to occur with datasets approaching 1 million rows in Chrome and unfortunately I have no workaround for it. If you have that many rows you definitely need some server side pagination and this is probably not the library for you.
|
|
139
142
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.data-table{--dt-header-sorter-width: 1ch;--dt-header-resizer-width: 10px;--dt-header-drop-color: rgba(255, 255, 255, .1);position:relative;white-space:nowrap;overflow:auto;table-layout:fixed}.dt-scroller{max-width:100%;max-height:100%;overflow:auto;position:relative}.dt-headers{position:sticky;top:0;z-index:1}.dt-headers th{overflow:hidden;box-sizing:border-box}.dt-headers .dt-header-content{position:relative}.dt-sortable .dt-header-content{cursor:pointer}.dt-header-title-wrapper{display:flex;flex-direction:row;align-items:center;flex-wrap:nowrap;overflow:hidden}.dt-sort-icon{position:relative;width:var(--dt-header-sorter-width);align-self:stretch;padding:0 12px;overflow:hidden;flex-shrink:0}.dt-sort-icon:after{content:"";position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.dt-sortable.dt-descending .dt-sort-icon:after{content:"\2191"}.dt-sortable.dt-ascending .dt-sort-icon:after{content:"\2193"}.dt-resizer{position:absolute;top:0;right:calc((var(--dt-header-resizer-width) / 2) * -1);height:100%;width:var(--dt-header-resizer-width);cursor:ew-resize;z-index:2}.dt-resizer:after{content:"";position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:1px;height:60%;background-color:currentColor}.dt-headers>tr>th.dt-drag-over,.dt-headers>tr>th:has(.dt-drag-over){background-color:var(--dt-header-drop-color)}.data-table>tbody>tr>td,.dt-header-title{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.dt-empty{text-align:center;pointer-events:none}
|
|
2
|
+
/*# sourceMappingURL=data-table.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/data-table/data-table.css"],"sourcesContent":[".data-table {\n --dt-header-sorter-width: 1ch;\n --dt-header-resizer-width: 10px;\n --dt-header-drop-color: rgba(255, 255, 255, 0.1);\n\n position: relative;\n white-space: nowrap;\n overflow: auto;\n table-layout: fixed;\n}\n\n.dt-scroller {\n max-width: 100%;\n max-height: 100%;\n overflow: auto;\n position: relative;\n}\n\n.dt-headers {\n position: sticky;\n top: 0;\n z-index: 1;\n}\n\n.dt-headers th {\n overflow: hidden;\n box-sizing: border-box;\n}\n\n.dt-headers .dt-header-content {\n position: relative;\n}\n\n.dt-sortable .dt-header-content {\n cursor: pointer;\n}\n\n.dt-header-title-wrapper {\n display: flex;\n flex-direction: row;\n align-items: center;\n flex-wrap: nowrap;\n overflow: hidden;\n}\n\n.dt-sort-icon {\n position: relative;\n width: var(--dt-header-sorter-width);\n align-self: stretch;\n padding: 0 12px;\n overflow: hidden;\n flex-shrink: 0;\n}\n\n.dt-sort-icon::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}\n\n.dt-sortable.dt-descending .dt-sort-icon::after {\n content: '\\2191';\n}\n\n.dt-sortable.dt-ascending .dt-sort-icon::after {\n content: '\\2193';\n}\n\n.dt-resizer {\n position: absolute;\n top: 0;\n right: calc((var(--dt-header-resizer-width) / 2) * -1);\n height: 100%;\n width: var(--dt-header-resizer-width);\n cursor: ew-resize;\n z-index: 2;\n}\n\n.dt-resizer::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 1px;\n height: 60%;\n background-color: currentColor;\n}\n\n.dt-headers > tr > th.dt-drag-over,\n.dt-headers > tr > th:has(.dt-drag-over) {\n background-color: var(--dt-header-drop-color);\n}\n\n.data-table > tbody > tr > td,\n.dt-header-title {\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n}\n\n.dt-empty {\n text-align: center;\n pointer-events: none;\n}\n"],"mappings":"AAAA,CAAC,WACC,0BAA0B,IAC1B,2BAA2B,KAC3B,wBAAwB,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAE5C,SAAU,SACV,YAAa,OACb,SAAU,KACV,aAAc,KAChB,CAEA,CAAC,YACC,UAAW,KACX,WAAY,KACZ,SAAU,KACV,SAAU,QACZ,CAEA,CAAC,WACC,SAAU,OACV,IAAK,EACL,QAAS,CACX,CAEA,CANC,WAMW,GACV,SAAU,OACV,WAAY,UACd,CAEA,CAXC,WAWW,CAAC,kBACX,SAAU,QACZ,CAEA,CAAC,YAAY,CAJA,kBAKX,OAAQ,OACV,CAEA,CAAC,wBACC,QAAS,KACT,eAAgB,IAChB,YAAa,OACb,UAAW,OACX,SAAU,MACZ,CAEA,CAAC,aACC,SAAU,SACV,MAAO,IAAI,0BACX,WAAY,QAhDd,QAiDW,EAAE,KACX,SAAU,OACV,YAAa,CACf,CAEA,CATC,YASY,OACX,QAAS,GACT,SAAU,SACV,IAAK,IACL,KAAM,IACN,UAAW,UAAU,IAAI,CAAE,KAC7B,CAEA,CA7BC,WA6BW,CAAC,cAAc,CAjB1B,YAiBuC,OACtC,QAAS,OACX,CAEA,CAjCC,WAiCW,CAAC,aAAa,CArBzB,YAqBsC,OACrC,QAAS,OACX,CAEA,CAAC,WACC,SAAU,SACV,IAAK,EACL,MAAO,KAAK,CAAC,IAAI,2BAA2B,EAAE,GAAG,EAAE,IACnD,OAAQ,KACR,MAAO,IAAI,2BACX,OAAQ,UACR,QAAS,CACX,CAEA,CAVC,UAUU,OACT,QAAS,GACT,SAAU,SACV,IAAK,IACL,KAAM,IACN,UAAW,UAAU,IAAI,CAAE,MAC3B,MAAO,IACP,OAAQ,IACR,iBAAkB,YACpB,CAEA,CAzEC,UAyEW,CAAE,EAAG,CAAE,EAAE,CAAC,aACtB,CA1EC,UA0EW,CAAE,EAAG,CAAE,EAAE,KAAK,CADJ,cAEpB,iBAAkB,IAAI,uBACxB,CAEA,CAhGC,UAgGW,CAAE,KAAM,CAAE,EAAG,CAAE,GAC3B,CAAC,gBACC,cAAe,SACf,YAAa,OACb,SAAU,MACZ,CAEA,CAAC,SACC,WAAY,OACZ,eAAgB,IAClB","names":[]}
|
|
@@ -1,15 +1,40 @@
|
|
|
1
|
-
type NestedKeyOf<
|
|
2
|
-
[
|
|
3
|
-
}[keyof
|
|
1
|
+
type NestedKeyOf<ObjectType extends object> = {
|
|
2
|
+
[Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object ? `${Key}` | `${Key}.${NestedKeyOf<ObjectType[Key]>}` : `${Key}`;
|
|
3
|
+
}[keyof ObjectType & (string | number)];
|
|
4
4
|
declare const createRegexTokenizer: (exp?: string) => (value: string) => {
|
|
5
5
|
value: string;
|
|
6
6
|
quoted: boolean;
|
|
7
7
|
}[];
|
|
8
8
|
|
|
9
|
+
interface VirtualScrollOptions {
|
|
10
|
+
generator: (index: number) => HTMLElement;
|
|
11
|
+
container: HTMLElement;
|
|
12
|
+
element?: HTMLElement;
|
|
13
|
+
nodePadding?: number;
|
|
14
|
+
}
|
|
15
|
+
interface IVirtualScroll {
|
|
16
|
+
start(rowCount: number): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
scrollToIndex(index: number): void;
|
|
19
|
+
scrollToPx(px: number): void;
|
|
20
|
+
}
|
|
21
|
+
interface IVirtualScrollConstructor {
|
|
22
|
+
new (options: VirtualScrollOptions): IVirtualScroll;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Defines options for loading data into the table
|
|
27
|
+
* */
|
|
28
|
+
interface LoadOptions {
|
|
29
|
+
/** If the data should replace or be added to the end of the current data */
|
|
30
|
+
append?: boolean;
|
|
31
|
+
/** If the current scroll position should be kept */
|
|
32
|
+
keepScroll?: boolean;
|
|
33
|
+
}
|
|
9
34
|
/**
|
|
10
35
|
* Defines the possible sorting orders for columns.
|
|
11
36
|
*/
|
|
12
|
-
type SortOrder = 'asc' | 'desc'
|
|
37
|
+
type SortOrder = 'asc' | 'desc';
|
|
13
38
|
/**
|
|
14
39
|
* Callback for formatting a row's HTML element.
|
|
15
40
|
* @param row - The row data.
|
|
@@ -25,6 +50,7 @@ type RowFormatterCallback<T> = (row: T, element: HTMLElement) => void;
|
|
|
25
50
|
type ValueFormatterCallback<T> = (value: any, row: T) => string;
|
|
26
51
|
/**
|
|
27
52
|
* Callback for formatting a cell's HTML element.
|
|
53
|
+
* Called when the cell is created but NOT when exporting to CSV.
|
|
28
54
|
* @param value - The value of the field.
|
|
29
55
|
* @param row - The row data.
|
|
30
56
|
* @param element - The cell element.
|
|
@@ -44,8 +70,25 @@ type ComparatorCallback = (a: any, b: any) => number;
|
|
|
44
70
|
* @returns The derived value for sorting (e.g., a number or a standardized string).
|
|
45
71
|
*/
|
|
46
72
|
type SortValueCallback = (value: any) => number | string;
|
|
73
|
+
/**
|
|
74
|
+
* A filter object containing keys for the fields to be filtered,
|
|
75
|
+
* and the values used to compare against.
|
|
76
|
+
*/
|
|
77
|
+
type Filters<T extends object> = Partial<{
|
|
78
|
+
[K in NestedKeyOf<T>]: any;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* A single query token derived from a larger string
|
|
82
|
+
*/
|
|
47
83
|
interface QueryToken {
|
|
84
|
+
/**
|
|
85
|
+
* The value to use for the token
|
|
86
|
+
*/
|
|
48
87
|
value: string;
|
|
88
|
+
/**
|
|
89
|
+
* If the token should be treated as quoted.
|
|
90
|
+
* Quoted tokens are searched for exactly, no partial matches.
|
|
91
|
+
*/
|
|
49
92
|
quoted: boolean;
|
|
50
93
|
}
|
|
51
94
|
/**
|
|
@@ -60,7 +103,7 @@ type TokenizerCallback = (value: any) => QueryToken[];
|
|
|
60
103
|
* @param index - The index of the row.
|
|
61
104
|
* @returns True if the row matches the filter, false otherwise.
|
|
62
105
|
*/
|
|
63
|
-
type FilterCallback = (row:
|
|
106
|
+
type FilterCallback<T> = (row: T, index: number) => boolean;
|
|
64
107
|
/**
|
|
65
108
|
* Callback for filtering a field value against the filter data.
|
|
66
109
|
* @param value - The value to filter.
|
|
@@ -68,10 +111,24 @@ type FilterCallback = (row: any, index: number) => boolean;
|
|
|
68
111
|
* @returns True if the value matches the filter, false otherwise.
|
|
69
112
|
*/
|
|
70
113
|
type ColumnFilterCallback = (value: any, filter: any) => boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Represents the current sort state
|
|
116
|
+
*/
|
|
117
|
+
interface SortState {
|
|
118
|
+
/**
|
|
119
|
+
* The sort order
|
|
120
|
+
*/
|
|
121
|
+
order: SortOrder;
|
|
122
|
+
/**
|
|
123
|
+
* The sort priority.
|
|
124
|
+
* Lower priority means
|
|
125
|
+
*/
|
|
126
|
+
priority: number;
|
|
127
|
+
}
|
|
71
128
|
/**
|
|
72
129
|
* Column options for the table.
|
|
73
130
|
*/
|
|
74
|
-
interface ColumnOptions<T> {
|
|
131
|
+
interface ColumnOptions<T extends object> {
|
|
75
132
|
/**
|
|
76
133
|
* The field name in the data object.
|
|
77
134
|
*/
|
|
@@ -92,65 +149,42 @@ interface ColumnOptions<T> {
|
|
|
92
149
|
* Whether the column's data should be tokenized for searching.
|
|
93
150
|
*/
|
|
94
151
|
tokenize?: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* The initial sort order of the column.
|
|
97
|
-
*/
|
|
98
|
-
sortOrder?: SortOrder;
|
|
99
|
-
/**
|
|
100
|
-
* The initial sort priority of the column for sorting.
|
|
101
|
-
* Lower numbers are sorted first.
|
|
102
|
-
*/
|
|
103
|
-
sortPriority?: number;
|
|
104
|
-
/**
|
|
105
|
-
* Whether the column should be visible by default.
|
|
106
|
-
*/
|
|
107
|
-
visible?: boolean;
|
|
108
152
|
/**
|
|
109
153
|
* Whether the column should be resizable.
|
|
110
|
-
* Defaults to the table's resizable option.
|
|
111
154
|
*/
|
|
112
155
|
resizable?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* The initial width of the column.
|
|
115
|
-
* Can be a number (in pixels) or a string (e.g. "100px", "50%").
|
|
116
|
-
*/
|
|
117
|
-
width?: string | number;
|
|
118
156
|
/**
|
|
119
157
|
* A function to format the value for display.
|
|
120
158
|
*/
|
|
121
|
-
valueFormatter?: ValueFormatterCallback<T
|
|
159
|
+
valueFormatter?: ValueFormatterCallback<T> | null;
|
|
122
160
|
/**
|
|
123
161
|
* A function to format the element for display.
|
|
124
162
|
*/
|
|
125
|
-
elementFormatter?: CellFormatterCallback<T
|
|
163
|
+
elementFormatter?: CellFormatterCallback<T> | null;
|
|
126
164
|
/**
|
|
127
165
|
* A function to use for sorting the column.
|
|
128
166
|
* This overrides the default sorting behavior.
|
|
129
167
|
*/
|
|
130
|
-
sorter?: ComparatorCallback;
|
|
168
|
+
sorter?: ComparatorCallback | null;
|
|
131
169
|
/**
|
|
132
170
|
* A function to derive a comparable value from the cell's original value, specifically for sorting this column.
|
|
133
171
|
* This can be used to preprocess and cache values (e.g., convert to lowercase, extract numbers) before comparison.
|
|
134
172
|
*/
|
|
135
|
-
sortValue?: SortValueCallback;
|
|
173
|
+
sortValue?: SortValueCallback | null;
|
|
136
174
|
/**
|
|
137
175
|
* A custom function to determine if a cell's value in this column matches a given filter criterion.
|
|
138
176
|
* This is used when `DataTable.filter()` is called with an object-based filter that targets this column's field.
|
|
139
|
-
* @param value - The cell's value.
|
|
140
|
-
* @param filterCriterion - The criterion provided for this column in the main filter object.
|
|
141
177
|
*/
|
|
142
|
-
filter?: ColumnFilterCallback;
|
|
178
|
+
filter?: ColumnFilterCallback | null;
|
|
143
179
|
}
|
|
144
|
-
/**
|
|
145
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Represents the current state of a column.
|
|
182
|
+
*/
|
|
183
|
+
interface ColumnState<T extends object> {
|
|
146
184
|
/**
|
|
147
185
|
* The unique field name of the column.
|
|
148
186
|
*/
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* The user friendly title of the column.
|
|
152
|
-
*/
|
|
153
|
-
readonly title: string;
|
|
187
|
+
field: NestedKeyOf<T>;
|
|
154
188
|
/**
|
|
155
189
|
* The current visibility of the column.
|
|
156
190
|
*/
|
|
@@ -158,16 +192,11 @@ interface ColumnState {
|
|
|
158
192
|
/**
|
|
159
193
|
* The current sort order of the column.
|
|
160
194
|
*/
|
|
161
|
-
|
|
195
|
+
sortState?: SortState | null;
|
|
162
196
|
/**
|
|
163
|
-
* The
|
|
164
|
-
* Lower numbers are sorted first.
|
|
197
|
+
* The currently set width of the column in pixels.
|
|
165
198
|
*/
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The currently set width of the column.
|
|
169
|
-
*/
|
|
170
|
-
width: string;
|
|
199
|
+
width?: number | null;
|
|
171
200
|
}
|
|
172
201
|
/**
|
|
173
202
|
* Defines CSS classes to be applied to different parts of the table.
|
|
@@ -205,11 +234,7 @@ interface TableClasses {
|
|
|
205
234
|
/**
|
|
206
235
|
* Options for configuring the table.
|
|
207
236
|
*/
|
|
208
|
-
interface TableOptions<T> {
|
|
209
|
-
/**
|
|
210
|
-
* The initial data to load into the table.
|
|
211
|
-
*/
|
|
212
|
-
data?: T[];
|
|
237
|
+
interface TableOptions<T extends object> {
|
|
213
238
|
/**
|
|
214
239
|
* Configures virtual scrolling.
|
|
215
240
|
*/
|
|
@@ -227,16 +252,6 @@ interface TableOptions<T> {
|
|
|
227
252
|
* Scoring is very computationally expensive...
|
|
228
253
|
*/
|
|
229
254
|
enableSearchScoring?: boolean;
|
|
230
|
-
/**
|
|
231
|
-
* Whether columns should be sortable by default.
|
|
232
|
-
* Can be overridden on individual columns.
|
|
233
|
-
*/
|
|
234
|
-
sortable?: boolean;
|
|
235
|
-
/**
|
|
236
|
-
* Whether columns should be resizable by default.
|
|
237
|
-
* Can be overridden on individual columns.
|
|
238
|
-
*/
|
|
239
|
-
resizable?: boolean;
|
|
240
255
|
/**
|
|
241
256
|
* Whether columns should be rearrangeable by drag and drop.
|
|
242
257
|
*/
|
|
@@ -245,7 +260,7 @@ interface TableOptions<T> {
|
|
|
245
260
|
* Additional fields to include in the search.
|
|
246
261
|
* Used for fields that are not displayed as columns.
|
|
247
262
|
*/
|
|
248
|
-
extraSearchFields?:
|
|
263
|
+
extraSearchFields?: NestedKeyOf<T>[];
|
|
249
264
|
/**
|
|
250
265
|
* The text to display when there is no data in the table.
|
|
251
266
|
*/
|
|
@@ -261,21 +276,48 @@ interface TableOptions<T> {
|
|
|
261
276
|
/**
|
|
262
277
|
* A function to format each row's HTML element.
|
|
263
278
|
*/
|
|
264
|
-
rowFormatter?: RowFormatterCallback<T
|
|
279
|
+
rowFormatter?: RowFormatterCallback<T> | null;
|
|
265
280
|
/**
|
|
266
281
|
* A function to use for tokenizing values for searching.
|
|
267
282
|
*/
|
|
268
283
|
tokenizer?: TokenizerCallback;
|
|
284
|
+
/**
|
|
285
|
+
* A specific virtual scroll class to use
|
|
286
|
+
*/
|
|
287
|
+
virtualScrollClass?: IVirtualScrollConstructor;
|
|
269
288
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Represents the current state of the table
|
|
291
|
+
*/
|
|
292
|
+
interface TableState<T extends object> {
|
|
293
|
+
/**
|
|
294
|
+
* A list of {@link ColumnState}s representing all of the columns in the table.
|
|
295
|
+
*/
|
|
296
|
+
columns: ColumnState<T>[];
|
|
297
|
+
/**
|
|
298
|
+
* The current query applied to the table or null if no query is applied.
|
|
299
|
+
*/
|
|
300
|
+
searchQuery: string | RegExp | null;
|
|
301
|
+
/**
|
|
302
|
+
* The current filters applied to the table or null if no filters are applied.
|
|
303
|
+
*/
|
|
304
|
+
filters: Filters<T> | FilterCallback<T> | null;
|
|
305
|
+
/**
|
|
306
|
+
* The current scroll position of the table
|
|
307
|
+
*/
|
|
308
|
+
scrollPosition: {
|
|
309
|
+
top: number;
|
|
310
|
+
left: number;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* The current column order represented as a list of their fields from left to right.
|
|
314
|
+
*/
|
|
315
|
+
columnOrder: NestedKeyOf<T>[];
|
|
275
316
|
}
|
|
276
|
-
type
|
|
277
|
-
|
|
278
|
-
|
|
317
|
+
type RestorableColumnState<T extends object> = Partial<Omit<ColumnState<T>, 'field'>> & Pick<ColumnState<T>, 'field'>;
|
|
318
|
+
type RestorableTableState<T extends object> = Partial<Omit<TableState<T>, 'columns'>> & {
|
|
319
|
+
columns?: RestorableColumnState<T>[];
|
|
320
|
+
};
|
|
279
321
|
|
|
280
322
|
/**
|
|
281
323
|
* Represents a dynamic and interactive table with features like sorting, searching, filtering,
|
|
@@ -300,7 +342,7 @@ type Filters<T> = Partial<{
|
|
|
300
342
|
* });
|
|
301
343
|
* ```
|
|
302
344
|
*/
|
|
303
|
-
declare class DataTable<T> extends EventTarget {
|
|
345
|
+
declare class DataTable<T extends object> extends EventTarget {
|
|
304
346
|
#private;
|
|
305
347
|
private static readonly MatchWeights;
|
|
306
348
|
private readonly DEFAULT_OPTIONS;
|
|
@@ -312,15 +354,11 @@ declare class DataTable<T> extends EventTarget {
|
|
|
312
354
|
* @throws {SyntaxError} If the table selector does not find an element.
|
|
313
355
|
* @throws {TypeError} If the provided table element is not an HTMLTableElement or if columns option is not an array.
|
|
314
356
|
*/
|
|
315
|
-
constructor(table: string | HTMLTableElement, columns:
|
|
316
|
-
get options(): RequiredOptions<T>;
|
|
357
|
+
constructor(table: string | HTMLTableElement, columns: ColumnInitOptions<T>[], options?: TableInitOptions<T>);
|
|
317
358
|
/**
|
|
318
|
-
* Gets
|
|
319
|
-
* This can be used to save and restore column configurations like visibility, sort order, and width.
|
|
320
|
-
* When setting, it attempts to apply the states to existing columns.
|
|
359
|
+
* Gets the current options applied to the table.
|
|
321
360
|
*/
|
|
322
|
-
get
|
|
323
|
-
set columnStates(states: ColumnState[]);
|
|
361
|
+
get tableOptions(): ConcreteTableOptions<T>;
|
|
324
362
|
/**
|
|
325
363
|
* Gets the currently filtered and sorted rows displayed in the table.
|
|
326
364
|
*/
|
|
@@ -333,8 +371,18 @@ declare class DataTable<T> extends EventTarget {
|
|
|
333
371
|
* Gets the underlying HTMLTableElement managed by this DataTable instance.
|
|
334
372
|
*/
|
|
335
373
|
get table(): HTMLTableElement;
|
|
336
|
-
|
|
337
|
-
|
|
374
|
+
/**
|
|
375
|
+
* Gets the current state of the table.
|
|
376
|
+
*/
|
|
377
|
+
getState(): TableState<T>;
|
|
378
|
+
/**
|
|
379
|
+
* Restores the table to the provided state.
|
|
380
|
+
* @param state - The state to restore the table to.
|
|
381
|
+
*/
|
|
382
|
+
restoreState(state: RestorableTableState<T>): void;
|
|
383
|
+
updateTableOptions(options: UpdatableTableOptions<T>): void;
|
|
384
|
+
getColumnOptions(column: NestedKeyOf<T>): Required<ColumnOptionsWithoutField<T>>;
|
|
385
|
+
updateColumnOptions(column: NestedKeyOf<T>, options: ColumnOptionsWithoutField<T>): void;
|
|
338
386
|
/**
|
|
339
387
|
* Loads data into the table
|
|
340
388
|
* @param rows - An array of data to be loaded
|
|
@@ -347,7 +395,7 @@ declare class DataTable<T> extends EventTarget {
|
|
|
347
395
|
* @param text - The text or HTML message to display.
|
|
348
396
|
* @param classes - A string or array of strings for CSS classes to apply to the message row.
|
|
349
397
|
*/
|
|
350
|
-
showMessage(text: string, classes: string
|
|
398
|
+
showMessage(text: string, ...classes: string[]): void;
|
|
351
399
|
/**
|
|
352
400
|
* Clears the current message and dispalsy the normal table data.
|
|
353
401
|
*/
|
|
@@ -357,7 +405,7 @@ declare class DataTable<T> extends EventTarget {
|
|
|
357
405
|
* The search is performed on columns marked as `searchable` and `extraSearchFields`.
|
|
358
406
|
* @param query - The search term (string) or a regular expression. An empty string clears the search.
|
|
359
407
|
*/
|
|
360
|
-
search(query?: string | RegExp): void;
|
|
408
|
+
search(query?: string | RegExp | null): void;
|
|
361
409
|
/**
|
|
362
410
|
* Applies filters to the table rows.
|
|
363
411
|
* Filters can be an object where keys are field names and values are the criteria to filter by,
|
|
@@ -365,30 +413,30 @@ declare class DataTable<T> extends EventTarget {
|
|
|
365
413
|
* @param filters - An object defining field-based filters or a custom filter callback function.
|
|
366
414
|
* @throws {TypeError} If `filters` is not an object or a function.
|
|
367
415
|
*/
|
|
368
|
-
filter(filters?: Filters<T> | FilterCallback): void;
|
|
416
|
+
filter(filters?: Filters<T> | FilterCallback<T> | null): void;
|
|
369
417
|
/**
|
|
370
418
|
* Sorts the table by a specified column and order.
|
|
371
419
|
* If `order` is `null`, the sort on this column is removed.
|
|
372
420
|
* @param colName - The field name of the column to sort by.
|
|
373
421
|
* @param order - The sort order: 'asc', 'desc', or `null` to remove sorting for this column.
|
|
374
422
|
*/
|
|
375
|
-
sort(colName:
|
|
423
|
+
sort(colName: NestedKeyOf<T>, order: SortOrder | null): void;
|
|
376
424
|
/**
|
|
377
425
|
* Sets the visibility of a specified column.
|
|
378
426
|
* @param colName - The field name of the column.
|
|
379
427
|
* @param visisble - `true` to show the column, `false` to hide it.
|
|
380
428
|
*/
|
|
381
|
-
setColumnVisibility(colName:
|
|
429
|
+
setColumnVisibility(colName: NestedKeyOf<T>, visisble: boolean): void;
|
|
382
430
|
/**
|
|
383
431
|
* Shows a previously hidden column.
|
|
384
432
|
* @param field - The field name of the column to show.
|
|
385
433
|
*/
|
|
386
|
-
showColumn(field:
|
|
434
|
+
showColumn(field: NestedKeyOf<T>): void;
|
|
387
435
|
/**
|
|
388
436
|
* Hides a visible column.
|
|
389
437
|
* @param field - The field name of the column to hide.
|
|
390
438
|
*/
|
|
391
|
-
hideColumn(field:
|
|
439
|
+
hideColumn(field: NestedKeyOf<T>): void;
|
|
392
440
|
/**
|
|
393
441
|
* Export the current visible table data to a CSV file.
|
|
394
442
|
* @param filename - The name of the file to save.
|
|
@@ -409,7 +457,7 @@ declare class DataTable<T> extends EventTarget {
|
|
|
409
457
|
* @param fields - An array of field names representing the new order of columns. Columns not included in the array will be placed at the end.
|
|
410
458
|
* @throws {TypeError} If `fields` is not an array.
|
|
411
459
|
*/
|
|
412
|
-
setColumnOrder(fields:
|
|
460
|
+
setColumnOrder(fields: NestedKeyOf<T>[]): void;
|
|
413
461
|
/**
|
|
414
462
|
* Refreshes the table display. This re-applies filters, sorting, and updates headers and rows.
|
|
415
463
|
*/
|
|
@@ -442,7 +490,7 @@ declare class DataTable<T> extends EventTarget {
|
|
|
442
490
|
* }
|
|
443
491
|
* ```
|
|
444
492
|
*/
|
|
445
|
-
updateRow(index: number, data: T): void;
|
|
493
|
+
updateRow(index: number, data: Partial<T>): void;
|
|
446
494
|
/**
|
|
447
495
|
* Deletes a row at a specific original index from the table.
|
|
448
496
|
* @param index - The original index of the row to delete.
|
|
@@ -454,14 +502,25 @@ declare class DataTable<T> extends EventTarget {
|
|
|
454
502
|
* @param callback - A function to execute. It receives the DataTable instance as its argument.
|
|
455
503
|
* @example dataTable.withoutUpdates(dt => { dt.sort('name', 'asc'); dt.filter({ age: '>30' }); });
|
|
456
504
|
*/
|
|
457
|
-
withoutUpdates(callback: (
|
|
505
|
+
withoutUpdates(callback: (dataTable: DataTable<T>) => void): void;
|
|
458
506
|
addEventListener<K extends keyof DataTableEventMap<T>>(type: K, listener: (this: DataTable<T>, ev: CustomEvent<DataTableEventMap<T>[K]>) => any, options?: boolean | AddEventListenerOptions): void;
|
|
459
507
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
508
|
+
private readonly TABLE_OPTION_CONFIGS;
|
|
509
|
+
private readonly COLUMN_OPTION_CONFIGS;
|
|
460
510
|
}
|
|
461
|
-
type
|
|
462
|
-
|
|
511
|
+
type TableInitOptions<T extends object> = TableOptions<T> & {
|
|
512
|
+
data?: T[];
|
|
513
|
+
};
|
|
514
|
+
type ColumnInitOptions<T extends object> = ColumnOptions<T> & Partial<ColumnState<T>>;
|
|
515
|
+
type ConcreteTableClasses = Required<{
|
|
463
516
|
[K in keyof TableClasses]: string[];
|
|
464
517
|
}>;
|
|
518
|
+
type ConcreteTableOptions<T extends object> = Required<Omit<TableOptions<T>, 'data' | 'classes' | 'virtualScroll'>> & {
|
|
519
|
+
classes: ConcreteTableClasses;
|
|
520
|
+
virtualScroll: number;
|
|
521
|
+
};
|
|
522
|
+
type UpdatableTableOptions<T extends object> = TableOptions<T>;
|
|
523
|
+
type ColumnOptionsWithoutField<T extends object> = Omit<ColumnOptions<T>, 'field'>;
|
|
465
524
|
/**
|
|
466
525
|
* Defines the mapping between event names and their detail object types.
|
|
467
526
|
*/
|
|
@@ -475,7 +534,7 @@ interface DataTableEventMap<T> {
|
|
|
475
534
|
'dt.rows.changed': object;
|
|
476
535
|
'dt.col.sort': {
|
|
477
536
|
column: string;
|
|
478
|
-
order: SortOrder;
|
|
537
|
+
order: SortOrder | null;
|
|
479
538
|
};
|
|
480
539
|
'dt.col.visibility': {
|
|
481
540
|
column: string;
|
|
@@ -490,31 +549,52 @@ interface DataTableEventMap<T> {
|
|
|
490
549
|
dropColumn: string;
|
|
491
550
|
order: string[];
|
|
492
551
|
};
|
|
552
|
+
'dt.search': {
|
|
553
|
+
query: string | RegExp | null;
|
|
554
|
+
};
|
|
493
555
|
}
|
|
494
|
-
type RequiredOptions<T> = Required<Omit<TableOptions<T>, 'columns' | 'data' | 'rowFormatter' | 'classes'>> & Pick<TableOptions<T>, 'rowFormatter'> & {
|
|
495
|
-
classes: InternalClasses;
|
|
496
|
-
virtualScroll: number;
|
|
497
|
-
};
|
|
498
|
-
type UpdatableOptions<T> = Pick<TableOptions<T>, 'virtualScroll' | 'highlightSearch' | 'tokenizeSearch' | 'enableSearchScoring' | 'rearrangeable' | 'extraSearchFields' | 'noMatchText' | 'noDataText' | 'classes'>;
|
|
499
|
-
type UpdateableColumnOptions<T> = Pick<ColumnOptions<T>, 'title' | 'searchable' | 'resizable' | 'sortable' | 'tokenize' | 'valueFormatter' | 'elementFormatter' | 'sorter'>;
|
|
500
556
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
557
|
+
declare class VirtualScroll implements IVirtualScroll {
|
|
558
|
+
#private;
|
|
559
|
+
static AVERAGE_RENDER_COUNT: number;
|
|
560
|
+
constructor({ generator, container, element, nodePadding, }: VirtualScrollOptions);
|
|
561
|
+
private get rowHeight();
|
|
562
|
+
get started(): boolean;
|
|
563
|
+
scrollToIndex(index: number): void;
|
|
564
|
+
/**
|
|
565
|
+
* @param px
|
|
566
|
+
*/
|
|
567
|
+
scrollToPx(px: number): void;
|
|
568
|
+
start(rowCount: number): void;
|
|
569
|
+
stop(): void;
|
|
506
570
|
}
|
|
571
|
+
declare class VirtualScrollError extends Error {
|
|
572
|
+
constructor(message: string);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
interface LocalStorageAdapterOptions {
|
|
576
|
+
saveSearch?: boolean;
|
|
577
|
+
saveColumnSorting?: boolean;
|
|
578
|
+
saveColumnOrder?: boolean;
|
|
579
|
+
saveColumnVisibility?: boolean;
|
|
580
|
+
saveColumnWidth?: boolean;
|
|
581
|
+
}
|
|
582
|
+
interface IDataTable<T extends object> extends EventTarget {
|
|
583
|
+
getState(): TableState<T>;
|
|
584
|
+
restoreState(state: RestorableTableState<T>): void;
|
|
585
|
+
}
|
|
586
|
+
|
|
507
587
|
/**
|
|
508
588
|
* Monitors a {@link DataTable} instance for changes and saves the state to local storage.
|
|
509
589
|
*/
|
|
510
|
-
declare class LocalStorageAdapter<T> {
|
|
590
|
+
declare class LocalStorageAdapter<T extends object> {
|
|
511
591
|
#private;
|
|
512
592
|
/**
|
|
513
593
|
* @param dataTable - The DataTable instance to monitor.
|
|
514
594
|
* @param storageKey - The key to use for saving the state in localStorage.
|
|
515
595
|
* @param options - The options for configuring what is stored.
|
|
516
596
|
*/
|
|
517
|
-
constructor(dataTable:
|
|
597
|
+
constructor(dataTable: IDataTable<T>, storageKey: string, options?: LocalStorageAdapterOptions);
|
|
518
598
|
/**
|
|
519
599
|
* Saves the current column state to localStorage.
|
|
520
600
|
*/
|
|
@@ -529,4 +609,4 @@ declare class LocalStorageAdapter<T> {
|
|
|
529
609
|
clearState(): void;
|
|
530
610
|
}
|
|
531
611
|
|
|
532
|
-
export { type CellFormatterCallback, type ColumnFilterCallback, type ColumnOptions, type ColumnState, type ComparatorCallback, DataTable, type DataTableEventMap, type FilterCallback, type Filters, type LoadOptions, LocalStorageAdapter, type QueryToken, type RowFormatterCallback, type SortOrder, type SortValueCallback, type TableClasses, type TableOptions, type TokenizerCallback, type ValueFormatterCallback, createRegexTokenizer };
|
|
612
|
+
export { type CellFormatterCallback, type ColumnFilterCallback, type ColumnOptions, type ColumnState, type ComparatorCallback, DataTable, type DataTableEventMap, type FilterCallback, type Filters, type IDataTable, type IVirtualScroll, type IVirtualScrollConstructor, type LoadOptions, LocalStorageAdapter, type LocalStorageAdapterOptions, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowFormatterCallback, type SortOrder, type SortState, type SortValueCallback, type TableClasses, type TableOptions, type TableState, type TokenizerCallback, type ValueFormatterCallback, VirtualScroll, VirtualScrollError, type VirtualScrollOptions, createRegexTokenizer };
|