@timlassiter11/yatl 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +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;width:100%;table-layout:fixed!important}.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}
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
2
  /*# sourceMappingURL=data-table.css.map */
@@ -1 +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 width: 100%;\n table-layout: fixed !important;\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,MAAO,KACP,aAAc,eAChB,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,QA1Cd,QA2CW,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,CA1FC,UA0FW,CAAE,KAAM,CAAE,EAAG,CAAE,GAC3B,CAAC,gBACC,cAAe,SACf,YAAa,OACb,SAAU,MACZ,CAEA,CAAC,SACC,WAAY,OACZ,eAAgB,IAClB","names":[]}
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":[]}
@@ -28,7 +28,7 @@ interface IVirtualScrollConstructor {
28
28
  interface LoadOptions {
29
29
  /** If the data should replace or be added to the end of the current data */
30
30
  append?: boolean;
31
- /** If the current scroll position should be kepts */
31
+ /** If the current scroll position should be kept */
32
32
  keepScroll?: boolean;
33
33
  }
34
34
  /**
@@ -40,21 +40,22 @@ type SortOrder = 'asc' | 'desc';
40
40
  * @param row - The row data.
41
41
  * @param element - The row element.
42
42
  */
43
- type RowFormatterCallback<T extends object> = (row: T, element: HTMLElement) => void;
43
+ type RowFormatterCallback<T> = (row: T, element: HTMLElement) => void;
44
44
  /**
45
45
  * Callback for formatting the value of a cell.
46
46
  * Called when the cell is created and when exporting to CSV.
47
47
  * @param value - The value of the cell.
48
48
  * @param row - The row data.
49
49
  */
50
- type ValueFormatterCallback<T extends object> = (value: any, row: T) => string;
50
+ type ValueFormatterCallback<T> = (value: any, row: T) => string | null;
51
51
  /**
52
52
  * Callback for formatting a cell's HTML element.
53
+ * Called when the cell is created but NOT when exporting to CSV.
53
54
  * @param value - The value of the field.
54
55
  * @param row - The row data.
55
56
  * @param element - The cell element.
56
57
  */
57
- type CellFormatterCallback<T extends object> = (value: any, row: T, element: HTMLElement) => void;
58
+ type CellFormatterCallback<T> = (value: any, row: T, element: HTMLElement) => void;
58
59
  /**
59
60
  * Callback for comparing two values.
60
61
  * @param a - The first value.
@@ -74,7 +75,7 @@ type SortValueCallback = (value: any) => number | string;
74
75
  * and the values used to compare against.
75
76
  */
76
77
  type Filters<T extends object> = Partial<{
77
- [K in keyof T]: any;
78
+ [K in NestedKeyOf<T>]: any;
78
79
  }>;
79
80
  /**
80
81
  * A single query token derived from a larger string
@@ -102,7 +103,7 @@ type TokenizerCallback = (value: any) => QueryToken[];
102
103
  * @param index - The index of the row.
103
104
  * @returns True if the row matches the filter, false otherwise.
104
105
  */
105
- type FilterCallback = (row: any, index: number) => boolean;
106
+ type FilterCallback<T> = (row: T, index: number) => boolean;
106
107
  /**
107
108
  * Callback for filtering a field value against the filter data.
108
109
  * @param value - The value to filter.
@@ -110,6 +111,20 @@ type FilterCallback = (row: any, index: number) => boolean;
110
111
  * @returns True if the value matches the filter, false otherwise.
111
112
  */
112
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
+ }
113
128
  /**
114
129
  * Column options for the table.
115
130
  */
@@ -134,13 +149,8 @@ interface ColumnOptions<T extends object> {
134
149
  * Whether the column's data should be tokenized for searching.
135
150
  */
136
151
  tokenize?: boolean;
137
- /**
138
- * Whether the column should be visible by default.
139
- */
140
- visible?: boolean;
141
152
  /**
142
153
  * Whether the column should be resizable.
143
- * Defaults to the table's resizable option.
144
154
  */
145
155
  resizable?: boolean;
146
156
  /**
@@ -167,6 +177,27 @@ interface ColumnOptions<T extends object> {
167
177
  */
168
178
  filter?: ColumnFilterCallback | null;
169
179
  }
180
+ /**
181
+ * Represents the current state of a column.
182
+ */
183
+ interface ColumnState<T extends object> {
184
+ /**
185
+ * The unique field name of the column.
186
+ */
187
+ field: NestedKeyOf<T>;
188
+ /**
189
+ * The current visibility of the column.
190
+ */
191
+ visible: boolean;
192
+ /**
193
+ * The current sort order of the column.
194
+ */
195
+ sortState?: SortState | null;
196
+ /**
197
+ * The currently set width of the column in pixels.
198
+ */
199
+ width?: number | null;
200
+ }
170
201
  /**
171
202
  * Defines CSS classes to be applied to different parts of the table.
172
203
  */
@@ -204,10 +235,6 @@ interface TableClasses {
204
235
  * Options for configuring the table.
205
236
  */
206
237
  interface TableOptions<T extends object> {
207
- /**
208
- * Data to load into the table
209
- */
210
- data?: T[];
211
238
  /**
212
239
  * Configures virtual scrolling.
213
240
  */
@@ -225,16 +252,6 @@ interface TableOptions<T extends object> {
225
252
  * Scoring is very computationally expensive...
226
253
  */
227
254
  enableSearchScoring?: boolean;
228
- /**
229
- * Whether columns should be sortable by default.
230
- * Can be overridden on individual columns.
231
- */
232
- sortable?: boolean;
233
- /**
234
- * Whether columns should be resizable by default.
235
- * Can be overridden on individual columns.
236
- */
237
- resizable?: boolean;
238
255
  /**
239
256
  * Whether columns should be rearrangeable by drag and drop.
240
257
  */
@@ -244,6 +261,10 @@ interface TableOptions<T extends object> {
244
261
  * Used for fields that are not displayed as columns.
245
262
  */
246
263
  extraSearchFields?: NestedKeyOf<T>[];
264
+ /**
265
+ * A placeholder to use for null or undefined values.
266
+ */
267
+ emptyValuePlaceholder?: string;
247
268
  /**
248
269
  * The text to display when there is no data in the table.
249
270
  */
@@ -264,53 +285,37 @@ interface TableOptions<T extends object> {
264
285
  * A function to use for tokenizing values for searching.
265
286
  */
266
287
  tokenizer?: TokenizerCallback;
288
+ /**
289
+ * A specific virtual scroll class to use
290
+ */
267
291
  virtualScrollClass?: IVirtualScrollConstructor;
268
292
  }
269
293
  /**
270
- * Represents the current sort state
294
+ * Represents the current state of the table
271
295
  */
272
- interface SortState {
273
- /**
274
- * The sort order
275
- */
276
- order: SortOrder;
277
- /**
278
- * The sort priority.
279
- * Lower priority means
280
- */
281
- priority: number;
282
- }
283
- /** Represents the current state of a column, often used for saving and restoring column configurations. */
284
- interface ColumnState<T extends object> {
296
+ interface TableState<T extends object> {
285
297
  /**
286
- * The unique field name of the column.
298
+ * A list of {@link ColumnState}s representing all of the columns in the table.
287
299
  */
288
- field: NestedKeyOf<T>;
300
+ columns: ColumnState<T>[];
289
301
  /**
290
- * The user friendly title of the column.
302
+ * The current query applied to the table or null if no query is applied.
291
303
  */
292
- title: string;
304
+ searchQuery: string | RegExp | null;
293
305
  /**
294
- * The current visibility of the column.
306
+ * The current filters applied to the table or null if no filters are applied.
295
307
  */
296
- visible: boolean;
308
+ filters: Filters<T> | FilterCallback<T> | null;
297
309
  /**
298
- * The current sort order of the column.
310
+ * The current scroll position of the table
299
311
  */
300
- sortState: SortState | null;
301
- /**
302
- * The currently set width of the column.
303
- */
304
- width: string;
305
- }
306
- interface TableState<T extends object> {
307
- columns: ColumnState<T>[];
308
- searchQuery?: string | RegExp;
309
- filters?: Filters<T> | FilterCallback;
310
312
  scrollPosition: {
311
313
  top: number;
312
314
  left: number;
313
315
  };
316
+ /**
317
+ * The current column order represented as a list of their fields from left to right.
318
+ */
314
319
  columnOrder: NestedKeyOf<T>[];
315
320
  }
316
321
  type RestorableColumnState<T extends object> = Partial<Omit<ColumnState<T>, 'field'>> & Pick<ColumnState<T>, 'field'>;
@@ -353,11 +358,11 @@ declare class DataTable<T extends object> extends EventTarget {
353
358
  * @throws {SyntaxError} If the table selector does not find an element.
354
359
  * @throws {TypeError} If the provided table element is not an HTMLTableElement or if columns option is not an array.
355
360
  */
356
- constructor(table: string | HTMLTableElement, columns: ColumnOptions<T>[], options?: TableOptions<T>);
361
+ constructor(table: string | HTMLTableElement, columns: ColumnInitOptions<T>[], options?: TableInitOptions<T>);
357
362
  /**
358
363
  * Gets the current options applied to the table.
359
364
  */
360
- get tableOptions(): RequiredTableOptions<T>;
365
+ get tableOptions(): ConcreteTableOptions<T>;
361
366
  /**
362
367
  * Gets the currently filtered and sorted rows displayed in the table.
363
368
  */
@@ -380,8 +385,8 @@ declare class DataTable<T extends object> extends EventTarget {
380
385
  */
381
386
  restoreState(state: RestorableTableState<T>): void;
382
387
  updateTableOptions(options: UpdatableTableOptions<T>): void;
383
- getColumnOptions(column: NestedKeyOf<T>): Required<Omit<ColumnOptions<T>, "field">>;
384
- updateColumnOptions(column: NestedKeyOf<T>, options: UpdateableColumnOptions<T>): void;
388
+ getColumnOptions(column: NestedKeyOf<T>): Required<ColumnOptionsWithoutField<T>>;
389
+ updateColumnOptions(column: NestedKeyOf<T>, options: ColumnOptionsWithoutField<T>): void;
385
390
  /**
386
391
  * Loads data into the table
387
392
  * @param rows - An array of data to be loaded
@@ -404,7 +409,7 @@ declare class DataTable<T extends object> extends EventTarget {
404
409
  * The search is performed on columns marked as `searchable` and `extraSearchFields`.
405
410
  * @param query - The search term (string) or a regular expression. An empty string clears the search.
406
411
  */
407
- search(query?: string | RegExp): void;
412
+ search(query?: string | RegExp | null): void;
408
413
  /**
409
414
  * Applies filters to the table rows.
410
415
  * Filters can be an object where keys are field names and values are the criteria to filter by,
@@ -412,7 +417,7 @@ declare class DataTable<T extends object> extends EventTarget {
412
417
  * @param filters - An object defining field-based filters or a custom filter callback function.
413
418
  * @throws {TypeError} If `filters` is not an object or a function.
414
419
  */
415
- filter(filters?: Filters<T> | FilterCallback): void;
420
+ filter(filters?: Filters<T> | FilterCallback<T> | null): void;
416
421
  /**
417
422
  * Sorts the table by a specified column and order.
418
423
  * If `order` is `null`, the sort on this column is removed.
@@ -504,7 +509,22 @@ declare class DataTable<T extends object> extends EventTarget {
504
509
  withoutUpdates(callback: (dataTable: DataTable<T>) => void): void;
505
510
  addEventListener<K extends keyof DataTableEventMap<T>>(type: K, listener: (this: DataTable<T>, ev: CustomEvent<DataTableEventMap<T>[K]>) => any, options?: boolean | AddEventListenerOptions): void;
506
511
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
512
+ private readonly TABLE_OPTION_CONFIGS;
513
+ private readonly COLUMN_OPTION_CONFIGS;
507
514
  }
515
+ type TableInitOptions<T extends object> = TableOptions<T> & {
516
+ data?: T[];
517
+ };
518
+ type ColumnInitOptions<T extends object> = ColumnOptions<T> & Partial<ColumnState<T>>;
519
+ type ConcreteTableClasses = Required<{
520
+ [K in keyof TableClasses]: string[];
521
+ }>;
522
+ type ConcreteTableOptions<T extends object> = Required<Omit<TableOptions<T>, 'data' | 'classes' | 'virtualScroll'>> & {
523
+ classes: ConcreteTableClasses;
524
+ virtualScroll: number;
525
+ };
526
+ type UpdatableTableOptions<T extends object> = TableOptions<T>;
527
+ type ColumnOptionsWithoutField<T extends object> = Omit<ColumnOptions<T>, 'field'>;
508
528
  /**
509
529
  * Defines the mapping between event names and their detail object types.
510
530
  */
@@ -537,15 +557,6 @@ interface DataTableEventMap<T> {
537
557
  query: string | RegExp | null;
538
558
  };
539
559
  }
540
- type ConcreteTableClasses = Required<{
541
- [K in keyof TableClasses]: string[];
542
- }>;
543
- type RequiredTableOptions<T extends object> = Required<Omit<TableOptions<T>, 'data' | 'classes' | 'virtualScroll'>> & {
544
- classes: ConcreteTableClasses;
545
- virtualScroll: number;
546
- };
547
- type UpdateableColumnOptions<T extends object> = Pick<ColumnOptions<T>, 'title' | 'searchable' | 'resizable' | 'sortable' | 'tokenize' | 'valueFormatter' | 'elementFormatter' | 'sorter'>;
548
- type UpdatableTableOptions<T extends object> = Pick<TableOptions<T>, 'virtualScroll' | 'highlightSearch' | 'tokenizeSearch' | 'enableSearchScoring' | 'rearrangeable' | 'extraSearchFields' | 'noMatchText' | 'noDataText' | 'classes'>;
549
560
 
550
561
  declare class VirtualScroll implements IVirtualScroll {
551
562
  #private;
@@ -567,7 +578,6 @@ declare class VirtualScrollError extends Error {
567
578
 
568
579
  interface LocalStorageAdapterOptions {
569
580
  saveSearch?: boolean;
570
- saveColumnTitle?: boolean;
571
581
  saveColumnSorting?: boolean;
572
582
  saveColumnOrder?: boolean;
573
583
  saveColumnVisibility?: boolean;
@@ -28,7 +28,7 @@ interface IVirtualScrollConstructor {
28
28
  interface LoadOptions {
29
29
  /** If the data should replace or be added to the end of the current data */
30
30
  append?: boolean;
31
- /** If the current scroll position should be kepts */
31
+ /** If the current scroll position should be kept */
32
32
  keepScroll?: boolean;
33
33
  }
34
34
  /**
@@ -40,21 +40,22 @@ type SortOrder = 'asc' | 'desc';
40
40
  * @param row - The row data.
41
41
  * @param element - The row element.
42
42
  */
43
- type RowFormatterCallback<T extends object> = (row: T, element: HTMLElement) => void;
43
+ type RowFormatterCallback<T> = (row: T, element: HTMLElement) => void;
44
44
  /**
45
45
  * Callback for formatting the value of a cell.
46
46
  * Called when the cell is created and when exporting to CSV.
47
47
  * @param value - The value of the cell.
48
48
  * @param row - The row data.
49
49
  */
50
- type ValueFormatterCallback<T extends object> = (value: any, row: T) => string;
50
+ type ValueFormatterCallback<T> = (value: any, row: T) => string | null;
51
51
  /**
52
52
  * Callback for formatting a cell's HTML element.
53
+ * Called when the cell is created but NOT when exporting to CSV.
53
54
  * @param value - The value of the field.
54
55
  * @param row - The row data.
55
56
  * @param element - The cell element.
56
57
  */
57
- type CellFormatterCallback<T extends object> = (value: any, row: T, element: HTMLElement) => void;
58
+ type CellFormatterCallback<T> = (value: any, row: T, element: HTMLElement) => void;
58
59
  /**
59
60
  * Callback for comparing two values.
60
61
  * @param a - The first value.
@@ -74,7 +75,7 @@ type SortValueCallback = (value: any) => number | string;
74
75
  * and the values used to compare against.
75
76
  */
76
77
  type Filters<T extends object> = Partial<{
77
- [K in keyof T]: any;
78
+ [K in NestedKeyOf<T>]: any;
78
79
  }>;
79
80
  /**
80
81
  * A single query token derived from a larger string
@@ -102,7 +103,7 @@ type TokenizerCallback = (value: any) => QueryToken[];
102
103
  * @param index - The index of the row.
103
104
  * @returns True if the row matches the filter, false otherwise.
104
105
  */
105
- type FilterCallback = (row: any, index: number) => boolean;
106
+ type FilterCallback<T> = (row: T, index: number) => boolean;
106
107
  /**
107
108
  * Callback for filtering a field value against the filter data.
108
109
  * @param value - The value to filter.
@@ -110,6 +111,20 @@ type FilterCallback = (row: any, index: number) => boolean;
110
111
  * @returns True if the value matches the filter, false otherwise.
111
112
  */
112
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
+ }
113
128
  /**
114
129
  * Column options for the table.
115
130
  */
@@ -134,13 +149,8 @@ interface ColumnOptions<T extends object> {
134
149
  * Whether the column's data should be tokenized for searching.
135
150
  */
136
151
  tokenize?: boolean;
137
- /**
138
- * Whether the column should be visible by default.
139
- */
140
- visible?: boolean;
141
152
  /**
142
153
  * Whether the column should be resizable.
143
- * Defaults to the table's resizable option.
144
154
  */
145
155
  resizable?: boolean;
146
156
  /**
@@ -167,6 +177,27 @@ interface ColumnOptions<T extends object> {
167
177
  */
168
178
  filter?: ColumnFilterCallback | null;
169
179
  }
180
+ /**
181
+ * Represents the current state of a column.
182
+ */
183
+ interface ColumnState<T extends object> {
184
+ /**
185
+ * The unique field name of the column.
186
+ */
187
+ field: NestedKeyOf<T>;
188
+ /**
189
+ * The current visibility of the column.
190
+ */
191
+ visible: boolean;
192
+ /**
193
+ * The current sort order of the column.
194
+ */
195
+ sortState?: SortState | null;
196
+ /**
197
+ * The currently set width of the column in pixels.
198
+ */
199
+ width?: number | null;
200
+ }
170
201
  /**
171
202
  * Defines CSS classes to be applied to different parts of the table.
172
203
  */
@@ -204,10 +235,6 @@ interface TableClasses {
204
235
  * Options for configuring the table.
205
236
  */
206
237
  interface TableOptions<T extends object> {
207
- /**
208
- * Data to load into the table
209
- */
210
- data?: T[];
211
238
  /**
212
239
  * Configures virtual scrolling.
213
240
  */
@@ -225,16 +252,6 @@ interface TableOptions<T extends object> {
225
252
  * Scoring is very computationally expensive...
226
253
  */
227
254
  enableSearchScoring?: boolean;
228
- /**
229
- * Whether columns should be sortable by default.
230
- * Can be overridden on individual columns.
231
- */
232
- sortable?: boolean;
233
- /**
234
- * Whether columns should be resizable by default.
235
- * Can be overridden on individual columns.
236
- */
237
- resizable?: boolean;
238
255
  /**
239
256
  * Whether columns should be rearrangeable by drag and drop.
240
257
  */
@@ -244,6 +261,10 @@ interface TableOptions<T extends object> {
244
261
  * Used for fields that are not displayed as columns.
245
262
  */
246
263
  extraSearchFields?: NestedKeyOf<T>[];
264
+ /**
265
+ * A placeholder to use for null or undefined values.
266
+ */
267
+ emptyValuePlaceholder?: string;
247
268
  /**
248
269
  * The text to display when there is no data in the table.
249
270
  */
@@ -264,53 +285,37 @@ interface TableOptions<T extends object> {
264
285
  * A function to use for tokenizing values for searching.
265
286
  */
266
287
  tokenizer?: TokenizerCallback;
288
+ /**
289
+ * A specific virtual scroll class to use
290
+ */
267
291
  virtualScrollClass?: IVirtualScrollConstructor;
268
292
  }
269
293
  /**
270
- * Represents the current sort state
294
+ * Represents the current state of the table
271
295
  */
272
- interface SortState {
273
- /**
274
- * The sort order
275
- */
276
- order: SortOrder;
277
- /**
278
- * The sort priority.
279
- * Lower priority means
280
- */
281
- priority: number;
282
- }
283
- /** Represents the current state of a column, often used for saving and restoring column configurations. */
284
- interface ColumnState<T extends object> {
296
+ interface TableState<T extends object> {
285
297
  /**
286
- * The unique field name of the column.
298
+ * A list of {@link ColumnState}s representing all of the columns in the table.
287
299
  */
288
- field: NestedKeyOf<T>;
300
+ columns: ColumnState<T>[];
289
301
  /**
290
- * The user friendly title of the column.
302
+ * The current query applied to the table or null if no query is applied.
291
303
  */
292
- title: string;
304
+ searchQuery: string | RegExp | null;
293
305
  /**
294
- * The current visibility of the column.
306
+ * The current filters applied to the table or null if no filters are applied.
295
307
  */
296
- visible: boolean;
308
+ filters: Filters<T> | FilterCallback<T> | null;
297
309
  /**
298
- * The current sort order of the column.
310
+ * The current scroll position of the table
299
311
  */
300
- sortState: SortState | null;
301
- /**
302
- * The currently set width of the column.
303
- */
304
- width: string;
305
- }
306
- interface TableState<T extends object> {
307
- columns: ColumnState<T>[];
308
- searchQuery?: string | RegExp;
309
- filters?: Filters<T> | FilterCallback;
310
312
  scrollPosition: {
311
313
  top: number;
312
314
  left: number;
313
315
  };
316
+ /**
317
+ * The current column order represented as a list of their fields from left to right.
318
+ */
314
319
  columnOrder: NestedKeyOf<T>[];
315
320
  }
316
321
  type RestorableColumnState<T extends object> = Partial<Omit<ColumnState<T>, 'field'>> & Pick<ColumnState<T>, 'field'>;
@@ -353,11 +358,11 @@ declare class DataTable<T extends object> extends EventTarget {
353
358
  * @throws {SyntaxError} If the table selector does not find an element.
354
359
  * @throws {TypeError} If the provided table element is not an HTMLTableElement or if columns option is not an array.
355
360
  */
356
- constructor(table: string | HTMLTableElement, columns: ColumnOptions<T>[], options?: TableOptions<T>);
361
+ constructor(table: string | HTMLTableElement, columns: ColumnInitOptions<T>[], options?: TableInitOptions<T>);
357
362
  /**
358
363
  * Gets the current options applied to the table.
359
364
  */
360
- get tableOptions(): RequiredTableOptions<T>;
365
+ get tableOptions(): ConcreteTableOptions<T>;
361
366
  /**
362
367
  * Gets the currently filtered and sorted rows displayed in the table.
363
368
  */
@@ -380,8 +385,8 @@ declare class DataTable<T extends object> extends EventTarget {
380
385
  */
381
386
  restoreState(state: RestorableTableState<T>): void;
382
387
  updateTableOptions(options: UpdatableTableOptions<T>): void;
383
- getColumnOptions(column: NestedKeyOf<T>): Required<Omit<ColumnOptions<T>, "field">>;
384
- updateColumnOptions(column: NestedKeyOf<T>, options: UpdateableColumnOptions<T>): void;
388
+ getColumnOptions(column: NestedKeyOf<T>): Required<ColumnOptionsWithoutField<T>>;
389
+ updateColumnOptions(column: NestedKeyOf<T>, options: ColumnOptionsWithoutField<T>): void;
385
390
  /**
386
391
  * Loads data into the table
387
392
  * @param rows - An array of data to be loaded
@@ -404,7 +409,7 @@ declare class DataTable<T extends object> extends EventTarget {
404
409
  * The search is performed on columns marked as `searchable` and `extraSearchFields`.
405
410
  * @param query - The search term (string) or a regular expression. An empty string clears the search.
406
411
  */
407
- search(query?: string | RegExp): void;
412
+ search(query?: string | RegExp | null): void;
408
413
  /**
409
414
  * Applies filters to the table rows.
410
415
  * Filters can be an object where keys are field names and values are the criteria to filter by,
@@ -412,7 +417,7 @@ declare class DataTable<T extends object> extends EventTarget {
412
417
  * @param filters - An object defining field-based filters or a custom filter callback function.
413
418
  * @throws {TypeError} If `filters` is not an object or a function.
414
419
  */
415
- filter(filters?: Filters<T> | FilterCallback): void;
420
+ filter(filters?: Filters<T> | FilterCallback<T> | null): void;
416
421
  /**
417
422
  * Sorts the table by a specified column and order.
418
423
  * If `order` is `null`, the sort on this column is removed.
@@ -504,7 +509,22 @@ declare class DataTable<T extends object> extends EventTarget {
504
509
  withoutUpdates(callback: (dataTable: DataTable<T>) => void): void;
505
510
  addEventListener<K extends keyof DataTableEventMap<T>>(type: K, listener: (this: DataTable<T>, ev: CustomEvent<DataTableEventMap<T>[K]>) => any, options?: boolean | AddEventListenerOptions): void;
506
511
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
512
+ private readonly TABLE_OPTION_CONFIGS;
513
+ private readonly COLUMN_OPTION_CONFIGS;
507
514
  }
515
+ type TableInitOptions<T extends object> = TableOptions<T> & {
516
+ data?: T[];
517
+ };
518
+ type ColumnInitOptions<T extends object> = ColumnOptions<T> & Partial<ColumnState<T>>;
519
+ type ConcreteTableClasses = Required<{
520
+ [K in keyof TableClasses]: string[];
521
+ }>;
522
+ type ConcreteTableOptions<T extends object> = Required<Omit<TableOptions<T>, 'data' | 'classes' | 'virtualScroll'>> & {
523
+ classes: ConcreteTableClasses;
524
+ virtualScroll: number;
525
+ };
526
+ type UpdatableTableOptions<T extends object> = TableOptions<T>;
527
+ type ColumnOptionsWithoutField<T extends object> = Omit<ColumnOptions<T>, 'field'>;
508
528
  /**
509
529
  * Defines the mapping between event names and their detail object types.
510
530
  */
@@ -537,15 +557,6 @@ interface DataTableEventMap<T> {
537
557
  query: string | RegExp | null;
538
558
  };
539
559
  }
540
- type ConcreteTableClasses = Required<{
541
- [K in keyof TableClasses]: string[];
542
- }>;
543
- type RequiredTableOptions<T extends object> = Required<Omit<TableOptions<T>, 'data' | 'classes' | 'virtualScroll'>> & {
544
- classes: ConcreteTableClasses;
545
- virtualScroll: number;
546
- };
547
- type UpdateableColumnOptions<T extends object> = Pick<ColumnOptions<T>, 'title' | 'searchable' | 'resizable' | 'sortable' | 'tokenize' | 'valueFormatter' | 'elementFormatter' | 'sorter'>;
548
- type UpdatableTableOptions<T extends object> = Pick<TableOptions<T>, 'virtualScroll' | 'highlightSearch' | 'tokenizeSearch' | 'enableSearchScoring' | 'rearrangeable' | 'extraSearchFields' | 'noMatchText' | 'noDataText' | 'classes'>;
549
560
 
550
561
  declare class VirtualScroll implements IVirtualScroll {
551
562
  #private;
@@ -567,7 +578,6 @@ declare class VirtualScrollError extends Error {
567
578
 
568
579
  interface LocalStorageAdapterOptions {
569
580
  saveSearch?: boolean;
570
- saveColumnTitle?: boolean;
571
581
  saveColumnSorting?: boolean;
572
582
  saveColumnOrder?: boolean;
573
583
  saveColumnVisibility?: boolean;