@nova-design-system/nova-react 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{constants-98e2dcc2-C0SBCapP.js → constants-b97e736d-BzFAKCkR.js} +11 -0
- package/dist/cjs/{index-Byv3Vmev.js → index-B2jv2KXv.js} +2856 -1620
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/{nv-alert.entry-BXY4KXbF.js → nv-alert.entry-pxBJfmIm.js} +11 -11
- package/dist/cjs/{nv-avatar.entry-BnPSKkJJ.js → nv-avatar.entry-CHtVctSK.js} +7 -7
- package/dist/cjs/nv-badge_2.entry-BO88KO1O.js +204 -0
- package/dist/cjs/{nv-breadcrumb.entry-D5vGHLOG.js → nv-breadcrumb.entry-7azRtyl5.js} +1 -1
- package/dist/cjs/{nv-breadcrumbs.entry-CsaqAsnb.js → nv-breadcrumbs.entry-DfZVMKpY.js} +1 -1
- package/dist/cjs/{nv-button.entry-DzZfGZGy.js → nv-button.entry-DW9SblsY.js} +7 -7
- package/dist/cjs/nv-calendar.entry-BeayRRor.js +1043 -0
- package/dist/cjs/{nv-col.entry-Cng8NaTW.js → nv-col.entry-C6oEkSbI.js} +1 -1
- package/dist/cjs/{nv-datagrid.entry-BbAOzpiO.js → nv-datagrid.entry-xhQP6JJP.js} +423 -94
- package/dist/cjs/{nv-datagridcolumn.entry-CRogHbVM.js → nv-datagridcolumn.entry-CjYmo4fM.js} +2 -2
- package/dist/cjs/{nv-dialog.entry-BSIZGYGF.js → nv-dialog.entry-mxETaZbc.js} +19 -13
- package/dist/cjs/{nv-dialogfooter_2.entry-Q4_li_QU.js → nv-dialogfooter_2.entry-DnLg2DHy.js} +3 -3
- package/dist/cjs/{nv-fieldcheckbox.entry-DmgzfmRd.js → nv-fieldcheckbox.entry-Be9__i15.js} +1 -1
- package/dist/cjs/{nv-fielddate.entry-qAvLX_Ru.js → nv-fielddate.entry-BlNily-X.js} +9 -18
- package/dist/cjs/nv-fielddaterange.entry-CycpKoJd.js +408 -0
- package/dist/cjs/{nv-fielddropdown.entry-DKXmoXeW.js → nv-fielddropdown.entry-BPwviyCp.js} +88 -57
- package/dist/cjs/{nv-fielddropdownitem.entry-BVLVXi0e.js → nv-fielddropdownitem.entry-BGuUR9KP.js} +2 -2
- package/dist/cjs/{nv-fieldmultiselect.entry-DrTbd3Dj.js → nv-fieldmultiselect.entry-Lrxr1gsi.js} +122 -104
- package/dist/cjs/nv-fieldnumber.entry-B1VySoWj.js +130 -0
- package/dist/cjs/nv-fieldpassword.entry-D7Qlx7Bh.js +121 -0
- package/dist/cjs/{nv-fieldradio.entry-CVEY4v6F.js → nv-fieldradio.entry-CDu8xs0p.js} +4 -4
- package/dist/cjs/{nv-fieldselect.entry-BrCUuRWa.js → nv-fieldselect.entry-NEdv8bQK.js} +11 -7
- package/dist/cjs/nv-fieldslider.entry-51gF9XPz.js +660 -0
- package/dist/cjs/nv-fieldtext.entry-Bug9zMgo.js +123 -0
- package/dist/cjs/{nv-fieldtextarea.entry-B4qiLmX1.js → nv-fieldtextarea.entry-D44HbsVQ.js} +9 -5
- package/dist/cjs/{nv-fieldtime.entry-Bp2IWjhN.js → nv-fieldtime.entry-MbaWbVtc.js} +71 -68
- package/dist/cjs/nv-icon.entry-BSSHr-ud.js +79 -0
- package/dist/cjs/{nv-iconbutton_2.entry-BRPAGl2S.js → nv-iconbutton_2.entry-DMaO-JWz.js} +3 -3
- package/dist/cjs/{nv-menu.entry-BiWiIZAm.js → nv-menu.entry-D5_lj9XB.js} +4 -2
- package/dist/cjs/{nv-menuitem.entry-CFkXoZ_r.js → nv-menuitem.entry-fhnYI91K.js} +2 -2
- package/dist/cjs/{nv-popover.entry-KT1iQUJk.js → nv-popover.entry-CYqBaVbr.js} +2 -2
- package/dist/cjs/{nv-row.entry-Cs2GDrcu.js → nv-row.entry-BUheLufV.js} +2 -2
- package/dist/cjs/{nv-stack.entry-Ci7pxGSo.js → nv-stack.entry-DNPce51E.js} +2 -2
- package/dist/cjs/{nv-table.entry-N4MV8Y6E.js → nv-table.entry-DXQM8l3t.js} +3 -3
- package/dist/cjs/{nv-tablecolumn.entry-CTz4jsZl.js → nv-tablecolumn.entry-DROQK_0c.js} +1 -1
- package/dist/cjs/{nv-toggle.entry-m10-ncYR.js → nv-toggle.entry-fMzTrdte.js} +3 -3
- package/dist/cjs/{nv-tooltip.entry-B6aRDto3.js → nv-tooltip.entry-yB2Ek1Cz.js} +3 -3
- package/dist/generated/components.js +12 -1
- package/dist/types/generated/components.d.ts +19 -7
- package/package.json +1 -1
- package/dist/cjs/nv-badge_2.entry-BsI3B8Rr.js +0 -195
- package/dist/cjs/nv-calendar.entry-CGKv_-gO.js +0 -1065
- package/dist/cjs/nv-fielddaterange.entry-DVB8Rwxk.js +0 -355
- package/dist/cjs/nv-fieldnumber.entry-DegbEHRL.js +0 -126
- package/dist/cjs/nv-fieldpassword.entry-gqjlEl7a.js +0 -117
- package/dist/cjs/nv-fieldtext.entry-q9NnqL5c.js +0 -119
- package/dist/cjs/nv-icon.entry-B1ax9cJS.js +0 -79
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-B2jv2KXv.js');
|
|
4
4
|
var dom_utilsAc71e0ef = require('./dom.utils-ac71e0ef-CmIwRr6O.js');
|
|
5
|
+
var constantsB97e736d = require('./constants-b97e736d-BzFAKCkR.js');
|
|
5
6
|
require('react');
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -3202,6 +3203,92 @@ function getPaginationRowModel(opts) {
|
|
|
3202
3203
|
}, getMemoOptions(table.options, 'debugTable'));
|
|
3203
3204
|
}
|
|
3204
3205
|
|
|
3206
|
+
function getSortedRowModel() {
|
|
3207
|
+
return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
|
|
3208
|
+
if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
|
|
3209
|
+
return rowModel;
|
|
3210
|
+
}
|
|
3211
|
+
const sortingState = table.getState().sorting;
|
|
3212
|
+
const sortedFlatRows = [];
|
|
3213
|
+
|
|
3214
|
+
// Filter out sortings that correspond to non existing columns
|
|
3215
|
+
const availableSorting = sortingState.filter(sort => {
|
|
3216
|
+
var _table$getColumn;
|
|
3217
|
+
return (_table$getColumn = table.getColumn(sort.id)) == null ? void 0 : _table$getColumn.getCanSort();
|
|
3218
|
+
});
|
|
3219
|
+
const columnInfoById = {};
|
|
3220
|
+
availableSorting.forEach(sortEntry => {
|
|
3221
|
+
const column = table.getColumn(sortEntry.id);
|
|
3222
|
+
if (!column) return;
|
|
3223
|
+
columnInfoById[sortEntry.id] = {
|
|
3224
|
+
sortUndefined: column.columnDef.sortUndefined,
|
|
3225
|
+
invertSorting: column.columnDef.invertSorting,
|
|
3226
|
+
sortingFn: column.getSortingFn()
|
|
3227
|
+
};
|
|
3228
|
+
});
|
|
3229
|
+
const sortData = rows => {
|
|
3230
|
+
// This will also perform a stable sorting using the row index
|
|
3231
|
+
// if needed.
|
|
3232
|
+
const sortedData = rows.map(row => ({
|
|
3233
|
+
...row
|
|
3234
|
+
}));
|
|
3235
|
+
sortedData.sort((rowA, rowB) => {
|
|
3236
|
+
for (let i = 0; i < availableSorting.length; i += 1) {
|
|
3237
|
+
var _sortEntry$desc;
|
|
3238
|
+
const sortEntry = availableSorting[i];
|
|
3239
|
+
const columnInfo = columnInfoById[sortEntry.id];
|
|
3240
|
+
const sortUndefined = columnInfo.sortUndefined;
|
|
3241
|
+
const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
|
|
3242
|
+
let sortInt = 0;
|
|
3243
|
+
|
|
3244
|
+
// All sorting ints should always return in ascending order
|
|
3245
|
+
if (sortUndefined) {
|
|
3246
|
+
const aValue = rowA.getValue(sortEntry.id);
|
|
3247
|
+
const bValue = rowB.getValue(sortEntry.id);
|
|
3248
|
+
const aUndefined = aValue === undefined;
|
|
3249
|
+
const bUndefined = bValue === undefined;
|
|
3250
|
+
if (aUndefined || bUndefined) {
|
|
3251
|
+
if (sortUndefined === 'first') return aUndefined ? -1 : 1;
|
|
3252
|
+
if (sortUndefined === 'last') return aUndefined ? 1 : -1;
|
|
3253
|
+
sortInt = aUndefined && bUndefined ? 0 : aUndefined ? sortUndefined : -sortUndefined;
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
if (sortInt === 0) {
|
|
3257
|
+
sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
// If sorting is non-zero, take care of desc and inversion
|
|
3261
|
+
if (sortInt !== 0) {
|
|
3262
|
+
if (isDesc) {
|
|
3263
|
+
sortInt *= -1;
|
|
3264
|
+
}
|
|
3265
|
+
if (columnInfo.invertSorting) {
|
|
3266
|
+
sortInt *= -1;
|
|
3267
|
+
}
|
|
3268
|
+
return sortInt;
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
return rowA.index - rowB.index;
|
|
3272
|
+
});
|
|
3273
|
+
|
|
3274
|
+
// If there are sub-rows, sort them
|
|
3275
|
+
sortedData.forEach(row => {
|
|
3276
|
+
var _row$subRows;
|
|
3277
|
+
sortedFlatRows.push(row);
|
|
3278
|
+
if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
|
|
3279
|
+
row.subRows = sortData(row.subRows);
|
|
3280
|
+
}
|
|
3281
|
+
});
|
|
3282
|
+
return sortedData;
|
|
3283
|
+
};
|
|
3284
|
+
return {
|
|
3285
|
+
rows: sortData(rowModel.rows),
|
|
3286
|
+
flatRows: sortedFlatRows,
|
|
3287
|
+
rowsById: rowModel.rowsById
|
|
3288
|
+
};
|
|
3289
|
+
}, getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () => table._autoResetPageIndex()));
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3205
3292
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3206
3293
|
/**
|
|
3207
3294
|
* Debounce function to prevent multiple calls in a short
|
|
@@ -3222,13 +3309,14 @@ function debounce(func, wait) {
|
|
|
3222
3309
|
};
|
|
3223
3310
|
}
|
|
3224
3311
|
|
|
3225
|
-
const nvDatagridCss = "nv-datagrid{display:block}nv-datagrid .hidden{display:none}nv-datagrid table{border-collapse:collapse;border-color:inherit;text-indent:0;width:100%}nv-datagrid th{text-align:left;border-bottom:1px solid var(--components-datagrid-header-border);height:var(--spacing-12);padding:var(--spacing-3) var(--spacing-4);font-size:var(--font-size-md);font-weight:700;color:var(--components-datagrid-header-text)}nv-datagrid td{border-bottom:1px solid var(--components-datagrid-body-border);height:var(--spacing-12);max-height:var(--spacing-14);padding:var(--spacing-2) var(--spacing-4);font-size:var(--font-size-md);font-weight:400;color:var(--components-datagrid-body-text);white-space:nowrap;text-overflow:ellipsis}nv-datagrid tbody>tr:hover{background:var(--color-interaction-container-neutral-background-hover)}";
|
|
3312
|
+
const nvDatagridCss = "nv-datagrid{--nv-datagrid-border-default:var(\n --components-form-field-border-default\n );--nv-datagrid-border-hover:var(--components-form-field-border-hover);--nv-datagrid-border-focus:var(--components-form-field-border-default);--nv-datagrid-background-default:var(\n --components-form-field-background-default\n );--nv-datagrid-background-checked:var(\n --components-form-field-background-checked\n );--nv-datagrid-background-disabled:var(\n --components-form-field-background-disabled\n );--nv-datagrid-color-checked:var(\n --components-form-shape-foreground-default\n );--nv-datagrid-color-disabled:var(\n --components-form-shape-foreground-disabled\n );--nv-datagrid-outline-color:var(--color-focus-brand);display:block}nv-datagrid .hidden{display:none}nv-datagrid table{border-collapse:collapse;border-color:inherit;text-indent:0;width:100%}nv-datagrid th{text-align:left;border-bottom:1px solid var(--components-datagrid-header-border);height:var(--spacing-12);padding:var(--spacing-3) var(--spacing-4);font-size:var(--font-size-md);font-weight:700;color:var(--components-datagrid-header-text)}nv-datagrid td{border-bottom:1px solid var(--components-datagrid-body-border);height:var(--spacing-12);max-height:var(--spacing-14);padding:var(--spacing-2) var(--spacing-4);font-size:var(--font-size-md);font-weight:400;color:var(--components-datagrid-body-text);white-space:nowrap;text-overflow:ellipsis}nv-datagrid tbody>tr:hover{background:var(--color-interaction-container-neutral-background-hover)}nv-datagrid .cursor-pointer{cursor:pointer}nv-datagrid .select-none{-webkit-user-select:none;user-select:none}nv-datagrid .search-container{display:flex}nv-datagrid .checkbox-container{position:relative;color:var(--nv-datagrid-color-checked)}nv-datagrid .checkbox-container input[type=checkbox][readonly]{opacity:0.5}nv-datagrid .checkbox-container:has(input[type=checkbox]:disabled:not([readonly])){color:var(--nv-datagrid-color-disabled)}nv-datagrid .checkbox-container input[type=checkbox]{appearance:none;position:relative;display:flex;width:var(--form-checkbox-size);height:var(--form-checkbox-size);flex-direction:column;align-items:flex-start;border-radius:var(--form-checkbox-radius);border-width:var(--form-checkbox-border-width);border-style:solid;border-color:var(--nv-datagrid-border-default);background:var(--nv-datagrid-background-default)}nv-datagrid .checkbox-container input[type=checkbox]:hover{border-color:var(--nv-datagrid-border-hover)}nv-datagrid .checkbox-container input[type=checkbox]:focus{border-color:var(--nv-datagrid-border-focus)}nv-datagrid .checkbox-container input[type=checkbox]:focus,nv-datagrid .checkbox-container input[type=checkbox]:focus-within{outline:none}nv-datagrid .checkbox-container input[type=checkbox]:focus-visible,nv-datagrid .checkbox-container input[type=checkbox]:has(:focus-visible){outline:calc(var(--focus-outline-stroke) * 1) solid var(--nv-datagrid-outline-color);outline-offset:calc(var(--focus-outline-offset) * 1)}nv-datagrid .checkbox-container input[type=checkbox]:checked,nv-datagrid .checkbox-container input[type=checkbox]:indeterminate{background:var(--nv-datagrid-background-checked);border-color:var(--nv-datagrid-background-checked)}nv-datagrid .checkbox-container input[type=checkbox]:disabled:not([readonly]){background:var(--nv-datagrid-background-disabled);border-color:var(--nv-datagrid-border-default)}nv-datagrid .checkbox-container input[type=checkbox][readonly]{opacity:0.5}nv-datagrid .checkbox-container .icon{pointer-events:none;position:absolute;top:0;left:0;width:100%;height:100%;display:flex;justify-content:center;align-items:center}nv-datagrid .checkbox-container .icon svg{width:var(--form-checkbox-icon-size);height:var(--form-checkbox-icon-size);fill:none;stroke:currentcolor;stroke-width:var(--form-checkbox-icon-stroke);flex-shrink:0}";
|
|
3226
3313
|
const NvDatagridStyle0 = nvDatagridCss;
|
|
3227
3314
|
|
|
3228
3315
|
const NvDatagrid = class {
|
|
3229
3316
|
constructor(hostRef) {
|
|
3230
3317
|
index.registerInstance(this, hostRef);
|
|
3231
3318
|
this.action = index.createEvent(this, "action");
|
|
3319
|
+
this.selectedRows = index.createEvent(this, "selectedRows");
|
|
3232
3320
|
this.templateCache = new Map();
|
|
3233
3321
|
this.headerTemplateCache = new Map();
|
|
3234
3322
|
this.minPageIndex = 1;
|
|
@@ -3240,6 +3328,8 @@ const NvDatagrid = class {
|
|
|
3240
3328
|
this.globalFilterSearchTerm = '';
|
|
3241
3329
|
this.columnData = [];
|
|
3242
3330
|
this.paginationState = null;
|
|
3331
|
+
this.sorting = [];
|
|
3332
|
+
this.rowSelectionState = {};
|
|
3243
3333
|
//#endregion STATES
|
|
3244
3334
|
/****************************************************************************/
|
|
3245
3335
|
//#region PROPERTIES
|
|
@@ -3275,6 +3365,12 @@ const NvDatagrid = class {
|
|
|
3275
3365
|
* @default 'No data or columns available to display.'
|
|
3276
3366
|
*/
|
|
3277
3367
|
this.noColumnsNoDataMessage = 'No data or columns available to display.';
|
|
3368
|
+
/**
|
|
3369
|
+
* Whether to automatically generate columns if none are provided.
|
|
3370
|
+
* If columns are explicitly set, this property is ignored.
|
|
3371
|
+
* @default false
|
|
3372
|
+
*/
|
|
3373
|
+
this.autoGenerateColumns = false;
|
|
3278
3374
|
/**
|
|
3279
3375
|
* Whether to enable global filtering for the data grid.
|
|
3280
3376
|
* This allows users to search across all columns for a specific value.
|
|
@@ -3284,11 +3380,9 @@ const NvDatagrid = class {
|
|
|
3284
3380
|
*/
|
|
3285
3381
|
this.enableGlobalFilter = false;
|
|
3286
3382
|
/**
|
|
3287
|
-
*
|
|
3288
|
-
* If columns are explicitly set, this property is ignored.
|
|
3289
|
-
* @default false
|
|
3383
|
+
* Position the global filter input field
|
|
3290
3384
|
*/
|
|
3291
|
-
this.
|
|
3385
|
+
this.globalFilterPosition = 'end';
|
|
3292
3386
|
/**
|
|
3293
3387
|
* Whether to enable pagination for the data grid.
|
|
3294
3388
|
* @default false
|
|
@@ -3296,6 +3390,7 @@ const NvDatagrid = class {
|
|
|
3296
3390
|
this.enablePagination = false;
|
|
3297
3391
|
/**
|
|
3298
3392
|
* The number of rows to display per page.
|
|
3393
|
+
* If the number is not present in the property pageSizes it takes the first of the list.
|
|
3299
3394
|
* @default 10
|
|
3300
3395
|
*/
|
|
3301
3396
|
this.pageSize = 10;
|
|
@@ -3304,6 +3399,15 @@ const NvDatagrid = class {
|
|
|
3304
3399
|
* @default [10, 20, 30, 40, 50]
|
|
3305
3400
|
*/
|
|
3306
3401
|
this.pageSizes = [10, 20, 30, 40, 50];
|
|
3402
|
+
/**
|
|
3403
|
+
* Whether to enable sorting for the data grid.
|
|
3404
|
+
* @default false
|
|
3405
|
+
*/
|
|
3406
|
+
this.enableSorting = false;
|
|
3407
|
+
/**
|
|
3408
|
+
* Whether to enable row selection for the data grid.
|
|
3409
|
+
*/
|
|
3410
|
+
this.enableRowSelection = false;
|
|
3307
3411
|
this.debouncedFilter = debounce((value) => {
|
|
3308
3412
|
var _a;
|
|
3309
3413
|
(_a = this.table) === null || _a === void 0 ? void 0 : _a.setGlobalFilter(value);
|
|
@@ -3336,8 +3440,32 @@ const NvDatagrid = class {
|
|
|
3336
3440
|
};
|
|
3337
3441
|
this.handlePageSizeChange = (event) => {
|
|
3338
3442
|
const target = event.target;
|
|
3443
|
+
let effectivePageSize = Number(target.value);
|
|
3444
|
+
if (!this.pageSizes.includes(effectivePageSize) && this.pageSizes) {
|
|
3445
|
+
effectivePageSize = this.pageSizes[0];
|
|
3446
|
+
}
|
|
3339
3447
|
// Simply use `setPageSize` to update the page size directly
|
|
3340
|
-
this.paginationState = Object.assign(Object.assign({}, this.paginationState), { pageSize:
|
|
3448
|
+
this.paginationState = Object.assign(Object.assign({}, this.paginationState), { pageSize: effectivePageSize }); // This triggers the paginationState watcher
|
|
3449
|
+
};
|
|
3450
|
+
this.handleSortingClick = (event, header) => {
|
|
3451
|
+
var _a;
|
|
3452
|
+
if (!header.column.getCanSort()) {
|
|
3453
|
+
return;
|
|
3454
|
+
}
|
|
3455
|
+
(_a = header.column.getToggleSortingHandler()) === null || _a === void 0 ? void 0 : _a(event);
|
|
3456
|
+
};
|
|
3457
|
+
this.getSortTitle = (header) => {
|
|
3458
|
+
if (!header.column.getCanSort())
|
|
3459
|
+
return;
|
|
3460
|
+
const nextOrder = header.column.getNextSortingOrder();
|
|
3461
|
+
switch (nextOrder) {
|
|
3462
|
+
case constantsB97e736d.SortingPossibility.Asc:
|
|
3463
|
+
return 'Sort ascending';
|
|
3464
|
+
case constantsB97e736d.SortingPossibility.Desc:
|
|
3465
|
+
return 'Sort descending';
|
|
3466
|
+
default:
|
|
3467
|
+
return 'Clear sort';
|
|
3468
|
+
}
|
|
3341
3469
|
};
|
|
3342
3470
|
}
|
|
3343
3471
|
//#endregion PROPERTIES
|
|
@@ -3373,34 +3501,37 @@ const NvDatagrid = class {
|
|
|
3373
3501
|
header: col.header,
|
|
3374
3502
|
accessor: col.accessor,
|
|
3375
3503
|
repeatTemplate: col.hasAttribute('repeat-template'),
|
|
3504
|
+
group: col.group,
|
|
3376
3505
|
};
|
|
3377
3506
|
this.columnData.push(colData);
|
|
3378
3507
|
});
|
|
3508
|
+
console.info('cacheTemplates this.columnData:', this.columnData);
|
|
3379
3509
|
}
|
|
3380
3510
|
parseDataAndColumns() {
|
|
3381
|
-
if (this.
|
|
3382
|
-
this.parseJsonData(this.dataJson);
|
|
3383
|
-
}
|
|
3384
|
-
else if (this.data && this.data.length > 0) {
|
|
3511
|
+
if (this.data && this.data.length > 0) {
|
|
3385
3512
|
this.parseDataArray(this.data, this.parsedData);
|
|
3386
3513
|
}
|
|
3387
|
-
if (this.
|
|
3388
|
-
this.parseJsonColumns(this.columnsJson, this.parsedColumns);
|
|
3389
|
-
}
|
|
3390
|
-
else if (this.columns && this.columns.length > 0) {
|
|
3514
|
+
if (this.columns && this.columns.length > 0) {
|
|
3391
3515
|
this.parseColumnsArray(this.columns, this.parsedColumns);
|
|
3392
3516
|
}
|
|
3393
3517
|
else if (this.headerTemplateCache.size > 0) {
|
|
3394
3518
|
const headerKeys = Array.from(this.headerTemplateCache.keys());
|
|
3395
|
-
const arrayColumnsConfig = headerKeys.map(key =>
|
|
3519
|
+
const arrayColumnsConfig = headerKeys.map(key => {
|
|
3520
|
+
var _a, _b;
|
|
3521
|
+
return (Object.assign({}, { accessor: key, header: key ? key.charAt(0).toUpperCase() + key.slice(1) : '', group: (_b = (_a = this.columnData.find(x => x.accessor === key)) === null || _a === void 0 ? void 0 : _a.group) !== null && _b !== void 0 ? _b : 'ungrouped' }));
|
|
3522
|
+
});
|
|
3396
3523
|
this.parseColumnsArray(arrayColumnsConfig, this.parsedColumns);
|
|
3397
3524
|
}
|
|
3398
3525
|
else if (this.parsedData.length > 0) {
|
|
3399
3526
|
const firstRow = this.parsedData[0];
|
|
3400
|
-
const arrayColumnsConfig = Object.keys(firstRow).map(key =>
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3527
|
+
const arrayColumnsConfig = Object.keys(firstRow).map(key => {
|
|
3528
|
+
var _a, _b;
|
|
3529
|
+
return ({
|
|
3530
|
+
accessor: key,
|
|
3531
|
+
header: key.charAt(0).toUpperCase() + key.slice(1),
|
|
3532
|
+
group: (_b = (_a = this.columnData.find(x => x.accessor === key)) === null || _a === void 0 ? void 0 : _a.group) !== null && _b !== void 0 ? _b : 'ungrouped',
|
|
3533
|
+
});
|
|
3534
|
+
});
|
|
3404
3535
|
if (this.autoGenerateColumns) {
|
|
3405
3536
|
this.parseColumnsArray(arrayColumnsConfig, this.parsedColumns);
|
|
3406
3537
|
}
|
|
@@ -3443,6 +3574,7 @@ const NvDatagrid = class {
|
|
|
3443
3574
|
var _a, _b, _c, _d;
|
|
3444
3575
|
// Clear the previous table instance (if any)
|
|
3445
3576
|
this.table = null;
|
|
3577
|
+
console.info('initializeTable this.columnData:', this.columnData);
|
|
3446
3578
|
// Set default options for the table
|
|
3447
3579
|
const tableOptions = {
|
|
3448
3580
|
columns: [],
|
|
@@ -3501,10 +3633,14 @@ const NvDatagrid = class {
|
|
|
3501
3633
|
if (hasData) {
|
|
3502
3634
|
// No parsed columns and data is available
|
|
3503
3635
|
const firstRow = this.parsedData[0];
|
|
3504
|
-
const arrayColumnsConfig = Object.keys(firstRow).map(key =>
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3636
|
+
const arrayColumnsConfig = Object.keys(firstRow).map(key => {
|
|
3637
|
+
var _a, _b;
|
|
3638
|
+
return ({
|
|
3639
|
+
accessor: key,
|
|
3640
|
+
header: key.charAt(0).toUpperCase() + key.slice(1),
|
|
3641
|
+
group: (_b = (_a = this.columnData.find(x => x.accessor === key)) === null || _a === void 0 ? void 0 : _a.group) !== null && _b !== void 0 ? _b : 'ungrouped',
|
|
3642
|
+
});
|
|
3643
|
+
});
|
|
3508
3644
|
if (this.autoGenerateColumns) {
|
|
3509
3645
|
this.parseColumnsArray(arrayColumnsConfig, this.parsedColumns);
|
|
3510
3646
|
}
|
|
@@ -3528,9 +3664,14 @@ const NvDatagrid = class {
|
|
|
3528
3664
|
}
|
|
3529
3665
|
if (this.enablePagination) {
|
|
3530
3666
|
tableOptions.getPaginationRowModel = getPaginationRowModel();
|
|
3667
|
+
const pageIndex = (_b = (_a = this.paginationState) === null || _a === void 0 ? void 0 : _a.pageIndex) !== null && _b !== void 0 ? _b : 0;
|
|
3668
|
+
let effectivePageSize = (_d = (_c = this.paginationState) === null || _c === void 0 ? void 0 : _c.pageSize) !== null && _d !== void 0 ? _d : 10;
|
|
3669
|
+
if (!this.pageSizes.includes(effectivePageSize) && this.pageSizes) {
|
|
3670
|
+
effectivePageSize = this.pageSizes[0];
|
|
3671
|
+
}
|
|
3531
3672
|
const pagination = {
|
|
3532
|
-
pageIndex:
|
|
3533
|
-
pageSize:
|
|
3673
|
+
pageIndex: pageIndex,
|
|
3674
|
+
pageSize: effectivePageSize,
|
|
3534
3675
|
};
|
|
3535
3676
|
// Set the initial pagination value with safeguards
|
|
3536
3677
|
tableOptions.state.pagination = pagination;
|
|
@@ -3541,6 +3682,33 @@ const NvDatagrid = class {
|
|
|
3541
3682
|
this.paginationState = newPagination;
|
|
3542
3683
|
};
|
|
3543
3684
|
}
|
|
3685
|
+
if (this.enableSorting) {
|
|
3686
|
+
tableOptions.getSortedRowModel = getSortedRowModel();
|
|
3687
|
+
tableOptions.enableSorting = this.enableSorting;
|
|
3688
|
+
tableOptions.state.sorting = this.sorting;
|
|
3689
|
+
tableOptions.onSortingChange = updater => {
|
|
3690
|
+
const newSorting = typeof updater === 'function' ? updater(this.sorting) : updater;
|
|
3691
|
+
this.sorting = newSorting; // Will automatically trigger the searchTerm watcher and update the table
|
|
3692
|
+
};
|
|
3693
|
+
}
|
|
3694
|
+
if (this.enableRowSelection) {
|
|
3695
|
+
tableOptions.state.rowSelection = this.rowSelectionState;
|
|
3696
|
+
tableOptions.onRowSelectionChange = updater => {
|
|
3697
|
+
const newRowSelectionState = typeof updater === 'function'
|
|
3698
|
+
? updater(this.rowSelectionState)
|
|
3699
|
+
: updater;
|
|
3700
|
+
this.rowSelectionState = newRowSelectionState;
|
|
3701
|
+
// Emit the original rows instead of IDs
|
|
3702
|
+
const selectedRows = Object.keys(newRowSelectionState)
|
|
3703
|
+
.filter(rowId => newRowSelectionState[rowId])
|
|
3704
|
+
.map(rowId => {
|
|
3705
|
+
// Assuming rowId corresponds to the index in parsedData
|
|
3706
|
+
const index = parseInt(rowId, 10); // Convert rowId to an integer index
|
|
3707
|
+
return this.parsedData[index]; // Get the original row data
|
|
3708
|
+
});
|
|
3709
|
+
this.selectedRows.emit(selectedRows); // Emit the original rows
|
|
3710
|
+
};
|
|
3711
|
+
}
|
|
3544
3712
|
// Initialize the table
|
|
3545
3713
|
this.table = createTable(tableOptions);
|
|
3546
3714
|
}
|
|
@@ -3575,60 +3743,165 @@ const NvDatagrid = class {
|
|
|
3575
3743
|
};
|
|
3576
3744
|
return checkValue(row.original);
|
|
3577
3745
|
}
|
|
3746
|
+
createIconSpan(checked, indeterminate) {
|
|
3747
|
+
const span = document.createElement('span');
|
|
3748
|
+
span.className = 'icon';
|
|
3749
|
+
if (checked && !indeterminate) {
|
|
3750
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
3751
|
+
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
3752
|
+
svg.setAttribute('width', '14');
|
|
3753
|
+
svg.setAttribute('height', '14');
|
|
3754
|
+
svg.setAttribute('viewBox', '0 0 14 14');
|
|
3755
|
+
svg.setAttribute('fill', 'none');
|
|
3756
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
3757
|
+
path.setAttribute('d', 'M11.6667 3.5L5.25004 9.91667L2.33337 7');
|
|
3758
|
+
path.setAttribute('stroke-linecap', 'round');
|
|
3759
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
3760
|
+
svg.appendChild(path);
|
|
3761
|
+
span.appendChild(svg);
|
|
3762
|
+
}
|
|
3763
|
+
if (indeterminate) {
|
|
3764
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
3765
|
+
svg.classList.add('indeterminate-svg');
|
|
3766
|
+
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
3767
|
+
svg.setAttribute('viewBox', '0 0 14 14');
|
|
3768
|
+
svg.setAttribute('fill', 'none');
|
|
3769
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
3770
|
+
path.setAttribute('d', 'M2.9165 7H11.0832');
|
|
3771
|
+
path.setAttribute('stroke-linecap', 'round');
|
|
3772
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
3773
|
+
svg.appendChild(path);
|
|
3774
|
+
span.appendChild(svg);
|
|
3775
|
+
}
|
|
3776
|
+
return span;
|
|
3777
|
+
}
|
|
3778
|
+
createIndeterminateCheckbox(options = {}) {
|
|
3779
|
+
const { indeterminate, checked = false, disabled = false, className = '', onChange, } = options;
|
|
3780
|
+
const input = document.createElement('input');
|
|
3781
|
+
input.type = 'checkbox';
|
|
3782
|
+
input.checked = checked;
|
|
3783
|
+
input.disabled = disabled;
|
|
3784
|
+
input.className = `${className} cursor-pointer`.trim();
|
|
3785
|
+
if (typeof indeterminate === 'boolean') {
|
|
3786
|
+
input.indeterminate = !checked && indeterminate;
|
|
3787
|
+
}
|
|
3788
|
+
if (onChange) {
|
|
3789
|
+
input.addEventListener('change', onChange);
|
|
3790
|
+
}
|
|
3791
|
+
const iconSpan = this.createIconSpan(checked, indeterminate);
|
|
3792
|
+
const container = document.createElement('div');
|
|
3793
|
+
container.className = 'checkbox-container';
|
|
3794
|
+
container.appendChild(input);
|
|
3795
|
+
container.appendChild(iconSpan);
|
|
3796
|
+
return container;
|
|
3797
|
+
}
|
|
3578
3798
|
// Helper function to generate column definitions
|
|
3579
3799
|
generateColumns(validColumns, tableOptions) {
|
|
3800
|
+
console.info('generateColumns this.columnData:', this.columnData);
|
|
3801
|
+
console.info('generateColumns validColumns:', validColumns);
|
|
3802
|
+
let processedColumns = validColumns || [];
|
|
3580
3803
|
const columnHelper = createColumnHelper();
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3804
|
+
// If no columns provided or autoGenerateColumns is true, generate them from data
|
|
3805
|
+
if ((!validColumns && tableOptions.data && tableOptions.data.length > 0) ||
|
|
3806
|
+
(validColumns.length <= 0 &&
|
|
3807
|
+
tableOptions.data &&
|
|
3808
|
+
tableOptions.data.length > 0)) {
|
|
3809
|
+
const sampleRow = tableOptions.data[0];
|
|
3810
|
+
processedColumns = Object.keys(sampleRow).map(key => {
|
|
3584
3811
|
var _a, _b;
|
|
3585
|
-
return
|
|
3586
|
-
header:
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
const cellAccessors = column.accessor;
|
|
3592
|
-
const row = info.row;
|
|
3593
|
-
return ((_a = this.columnData.find(x => x.accessor === cellAccessors)) === null || _a === void 0 ? void 0 : _a.repeatTemplate) && Array.isArray(value)
|
|
3594
|
-
? value.map((item) => {
|
|
3595
|
-
var _a, _b;
|
|
3596
|
-
return (_b = (_a = (this.renderTemplate(this.templateCache.get(cellAccessors), item, row) ||
|
|
3597
|
-
item)) !== null && _a !== void 0 ? _a : value) !== null && _b !== void 0 ? _b : this.fallbackValue;
|
|
3598
|
-
})
|
|
3599
|
-
: (_c = (_b = (this.renderTemplate(this.templateCache.get(cellAccessors), value, row) ||
|
|
3600
|
-
value)) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : this.fallbackValue;
|
|
3601
|
-
},
|
|
3602
|
-
enableGlobalFilter: this.enableGlobalFilter,
|
|
3812
|
+
return ({
|
|
3813
|
+
header: key.charAt(0).toUpperCase() + key.slice(1),
|
|
3814
|
+
accessor: key,
|
|
3815
|
+
group: (_b = (_a = this.columnData.find(x => x.accessor === key)) === null || _a === void 0 ? void 0 : _a.group) !== null && _b !== void 0 ? _b : 'ungrouped',
|
|
3816
|
+
headerSlot: null,
|
|
3817
|
+
cellSlot: null,
|
|
3603
3818
|
});
|
|
3604
3819
|
});
|
|
3605
3820
|
}
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3821
|
+
// Group columns by their group property
|
|
3822
|
+
const groupedColumns = processedColumns.reduce((acc, column) => {
|
|
3823
|
+
let group = column.group || 'ungrouped';
|
|
3824
|
+
if (group == 'ungrouped') {
|
|
3825
|
+
group = group + processedColumns.findIndex(x => x == column);
|
|
3826
|
+
}
|
|
3827
|
+
if (!acc[group]) {
|
|
3828
|
+
acc[group] = [];
|
|
3829
|
+
}
|
|
3830
|
+
acc[group].push(column);
|
|
3831
|
+
return acc;
|
|
3832
|
+
}, {});
|
|
3833
|
+
// Transform each column into a ColumnDef
|
|
3834
|
+
const createColumnDef = (column) => {
|
|
3835
|
+
var _a, _b, _c;
|
|
3836
|
+
return columnHelper.accessor(column.accessor, {
|
|
3837
|
+
header: (_c = (_b = this.renderTemplate(this.headerTemplateCache.get(column.accessor), (_a = column.header) !== null && _a !== void 0 ? _a : column.accessor, null)) !== null && _b !== void 0 ? _b : column.header) !== null && _c !== void 0 ? _c : column.accessor,
|
|
3611
3838
|
cell: (info) => {
|
|
3612
3839
|
var _a, _b, _c;
|
|
3613
3840
|
const value = info.getValue();
|
|
3614
|
-
const cellAccessors = key;
|
|
3615
3841
|
const row = info.row;
|
|
3616
|
-
return ((_a = this.columnData.find(x => x.accessor ===
|
|
3842
|
+
return ((_a = this.columnData.find(x => x.accessor === column.accessor)) === null || _a === void 0 ? void 0 : _a.repeatTemplate) && Array.isArray(value)
|
|
3617
3843
|
? value.map((item) => {
|
|
3618
|
-
var _a, _b;
|
|
3619
|
-
return (_b = (_a =
|
|
3620
|
-
item)) !== null && _a !== void 0 ? _a : value) !== null && _b !== void 0 ? _b : this.fallbackValue;
|
|
3844
|
+
var _a, _b, _c;
|
|
3845
|
+
return (_c = (_b = (_a = this.renderTemplate(this.templateCache.get(column.accessor), item, row)) !== null && _a !== void 0 ? _a : item) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : this.fallbackValue;
|
|
3621
3846
|
})
|
|
3622
|
-
: (_c = (_b =
|
|
3623
|
-
value)) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : this.fallbackValue;
|
|
3847
|
+
: (_c = (_b = this.renderTemplate(this.templateCache.get(column.accessor), value, row)) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : this.fallbackValue;
|
|
3624
3848
|
},
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3849
|
+
sortUndefined: 'last',
|
|
3850
|
+
sortDescFirst: false,
|
|
3851
|
+
enableSorting: this.enableSorting, // Explicitly set enableSorting based on the sorting prop
|
|
3852
|
+
enableGlobalFilter: this.enableGlobalFilter, // Explicity set enableGlobalFilter based on the globalFiltering prop
|
|
3853
|
+
});
|
|
3854
|
+
};
|
|
3855
|
+
// Create the final column structure
|
|
3856
|
+
let generatedColumns = Object.entries(groupedColumns)
|
|
3857
|
+
.map(([groupName, groupColumns]) => {
|
|
3858
|
+
if (groupName.includes('ungrouped')) {
|
|
3859
|
+
return groupColumns.map(createColumnDef);
|
|
3860
|
+
}
|
|
3861
|
+
return {
|
|
3862
|
+
id: groupName,
|
|
3863
|
+
header: groupName,
|
|
3864
|
+
columns: groupColumns.map(createColumnDef),
|
|
3865
|
+
enableSorting: this.enableSorting, // Also apply to column groups
|
|
3866
|
+
enableGlobalFilter: this.enableGlobalFilter, // Also apply to column groups
|
|
3867
|
+
};
|
|
3868
|
+
})
|
|
3869
|
+
.flat();
|
|
3870
|
+
if (this.enableRowSelection) {
|
|
3871
|
+
const rowSelection = columnHelper.accessor('select', {
|
|
3872
|
+
header: ({ table }) => {
|
|
3873
|
+
return (index.h("div", { class: "flex px-1", ref: el => {
|
|
3874
|
+
const checkbox = this.createIndeterminateCheckbox({
|
|
3875
|
+
checked: table === null || table === void 0 ? void 0 : table.getIsAllRowsSelected(),
|
|
3876
|
+
indeterminate: table === null || table === void 0 ? void 0 : table.getIsSomeRowsSelected(),
|
|
3877
|
+
onChange: table === null || table === void 0 ? void 0 : table.getToggleAllRowsSelectedHandler(),
|
|
3878
|
+
});
|
|
3879
|
+
if (el) {
|
|
3880
|
+
el.innerHTML = ''; // Remove existing content
|
|
3881
|
+
el.appendChild(checkbox); // Append new checkbox
|
|
3882
|
+
}
|
|
3883
|
+
} }));
|
|
3884
|
+
},
|
|
3885
|
+
cell: ({ row }) => {
|
|
3886
|
+
return (index.h("div", { class: "flex px-1", ref: el => {
|
|
3887
|
+
const checkbox = this.createIndeterminateCheckbox({
|
|
3888
|
+
checked: row === null || row === void 0 ? void 0 : row.getIsSelected(),
|
|
3889
|
+
disabled: !(row === null || row === void 0 ? void 0 : row.getCanSelect()),
|
|
3890
|
+
indeterminate: row === null || row === void 0 ? void 0 : row.getIsSomeSelected(),
|
|
3891
|
+
onChange: row === null || row === void 0 ? void 0 : row.getToggleSelectedHandler(),
|
|
3892
|
+
});
|
|
3893
|
+
if (el) {
|
|
3894
|
+
el.innerHTML = ''; // Remove existing content
|
|
3895
|
+
el.appendChild(checkbox); // Append new checkbox
|
|
3896
|
+
}
|
|
3897
|
+
} }));
|
|
3898
|
+
},
|
|
3899
|
+
enableGlobalFilter: false,
|
|
3900
|
+
enableSorting: false,
|
|
3901
|
+
});
|
|
3902
|
+
generatedColumns = [rowSelection, ...generatedColumns];
|
|
3631
3903
|
}
|
|
3904
|
+
return generatedColumns;
|
|
3632
3905
|
}
|
|
3633
3906
|
getTableData() {
|
|
3634
3907
|
if (this.parsedData &&
|
|
@@ -3876,35 +4149,55 @@ const NvDatagrid = class {
|
|
|
3876
4149
|
});
|
|
3877
4150
|
}
|
|
3878
4151
|
}
|
|
4152
|
+
getArrowSorting(header) {
|
|
4153
|
+
if (!header.column.getCanSort())
|
|
4154
|
+
return null;
|
|
4155
|
+
const sortState = header.column.getIsSorted();
|
|
4156
|
+
if (sortState === constantsB97e736d.SortingPossibility.Asc) {
|
|
4157
|
+
return (index.h("div", { class: "inline-flex align-middle" }, index.h("nv-icon", { name: "arrow-up" })));
|
|
4158
|
+
}
|
|
4159
|
+
if (sortState === constantsB97e736d.SortingPossibility.Desc) {
|
|
4160
|
+
return (index.h("div", { class: "inline-flex align-middle" }, index.h("nv-icon", { name: "arrow-down" })));
|
|
4161
|
+
}
|
|
4162
|
+
return null;
|
|
4163
|
+
}
|
|
4164
|
+
getHeaderCell(header) {
|
|
4165
|
+
const isSortable = header.column.getCanSort();
|
|
4166
|
+
const sortTitle = this.getSortTitle(header);
|
|
4167
|
+
const content = header.isPlaceholder
|
|
4168
|
+
? null
|
|
4169
|
+
: header.column.columnDef.header
|
|
4170
|
+
? this.flexRender(header.column.columnDef.header, header.getContext())
|
|
4171
|
+
: null; // Ensure content is not null
|
|
4172
|
+
const sortIcon = this.getArrowSorting(header);
|
|
4173
|
+
const handleClick = this.createSortingClickHandler(header);
|
|
4174
|
+
if (this.enableRowSelection) {
|
|
4175
|
+
return (index.h("th", { key: header.id, colSpan: header.colSpan }, content, " "));
|
|
4176
|
+
}
|
|
4177
|
+
const returnHtml = (index.h("th", { key: header.id, colSpan: header.colSpan }, index.h("button", { type: "button", class: isSortable
|
|
4178
|
+
? 'w-full text-left cursor-pointer select-none bg-transparent border-none p-0 m-0 focus:outline-none'
|
|
4179
|
+
: 'w-full text-left bg-transparent border-none p-0 m-0 cursor-default', onClick: handleClick, title: sortTitle }, index.h("span", { class: "inline-flex items-center gap-1" }, content, sortIcon))));
|
|
4180
|
+
return returnHtml;
|
|
4181
|
+
}
|
|
4182
|
+
// 👇 Helper method to avoid arrow function in JSX
|
|
4183
|
+
createSortingClickHandler(header) {
|
|
4184
|
+
return (e) => {
|
|
4185
|
+
this.handleSortingClick(e, header);
|
|
4186
|
+
};
|
|
4187
|
+
}
|
|
4188
|
+
getPagination() {
|
|
4189
|
+
var _a;
|
|
4190
|
+
return (this.enablePagination && (index.h("div", { class: "flex items-center gap-2" }, index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanPreviousPage(), onClick: this.table.firstPage }, "<<"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanPreviousPage(), onClick: this.table.previousPage }, "<"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanNextPage(), onClick: this.table.nextPage }, ">"), index.h("button", { class: "border rounded p-1", disabled: !this.table.getCanNextPage(), onClick: this.table.lastPage }, ">>"), index.h("span", { class: "flex items-center gap-1" }, index.h("div", null, "Page"), index.h("strong", null, this.table.getState().pagination.pageIndex + 1, " of", ' ', this.table.getPageCount().toLocaleString())), index.h("span", { class: "flex items-center gap-1" }, "| Go to page:", ' ', index.h("input", { type: "number", min: this.minPageIndex, max: this.table.getPageCount(), value: this.table.getState().pagination.pageIndex + 1, class: "border p-1 rounded w-16", "aria-label": "Go to page", onInput: this.handlePageIndexChange })), ((_a = this.pageSizes) === null || _a === void 0 ? void 0 : _a.length) > 0 && (index.h("select", { "aria-label": "Rows per page", onChange: this.handlePageSizeChange }, this.pageSizes.map(pageSize => (index.h("option", { value: String(pageSize), selected: this.table.getState().pagination.pageSize === pageSize }, "Show ", pageSize))))))));
|
|
4191
|
+
}
|
|
3879
4192
|
//#endregion METHODS
|
|
3880
4193
|
/****************************************************************************/
|
|
3881
4194
|
//#region WATCHERS
|
|
3882
4195
|
parseColumns(newValue, oldValue = []) {
|
|
3883
4196
|
this.parseColumnsArray(newValue, oldValue);
|
|
3884
4197
|
}
|
|
3885
|
-
parseJsonColumns(newValue, oldValue) {
|
|
3886
|
-
try {
|
|
3887
|
-
const newItems = newValue ? JSON.parse(newValue) : [];
|
|
3888
|
-
this.parseColumnsArray(newItems, oldValue);
|
|
3889
|
-
}
|
|
3890
|
-
catch (e) {
|
|
3891
|
-
console.error('Invalid JSON format for columnsJson:', e.message);
|
|
3892
|
-
this.parsedColumns = [];
|
|
3893
|
-
}
|
|
3894
|
-
}
|
|
3895
4198
|
parseData(newValue, oldValue = []) {
|
|
3896
4199
|
this.parseDataArray(newValue, oldValue);
|
|
3897
4200
|
}
|
|
3898
|
-
parseJsonData(newValue) {
|
|
3899
|
-
try {
|
|
3900
|
-
const newItems = newValue ? JSON.parse(newValue) : [];
|
|
3901
|
-
this.parseDataArray(newItems, this.parsedData);
|
|
3902
|
-
}
|
|
3903
|
-
catch (e) {
|
|
3904
|
-
console.error('Invalid JSON format for dataJson:', e.message);
|
|
3905
|
-
this.parsedData = [];
|
|
3906
|
-
}
|
|
3907
|
-
}
|
|
3908
4201
|
handleParsedChange() {
|
|
3909
4202
|
this.initializeTable();
|
|
3910
4203
|
}
|
|
@@ -3933,6 +4226,39 @@ const NvDatagrid = class {
|
|
|
3933
4226
|
this.table.options.state.pagination = newValue;
|
|
3934
4227
|
}
|
|
3935
4228
|
}
|
|
4229
|
+
handleSorting(newValue) {
|
|
4230
|
+
if (!this.table) {
|
|
4231
|
+
console.warn('Table is not initialized yet.');
|
|
4232
|
+
return;
|
|
4233
|
+
}
|
|
4234
|
+
// Not working
|
|
4235
|
+
/*// Set the sorting for the table
|
|
4236
|
+
this.table.setSorting(newValue);*/
|
|
4237
|
+
// Manually update the sorting state
|
|
4238
|
+
this.table.options.state.sorting = newValue;
|
|
4239
|
+
}
|
|
4240
|
+
handlePageSize(newValue) {
|
|
4241
|
+
let effectivePageSize = newValue;
|
|
4242
|
+
if (!this.pageSizes.includes(effectivePageSize) && this.pageSizes) {
|
|
4243
|
+
effectivePageSize = this.pageSizes[0];
|
|
4244
|
+
}
|
|
4245
|
+
// Simply use `setPageSize` to update the page size directly
|
|
4246
|
+
this.paginationState = Object.assign(Object.assign({}, this.paginationState), { pageSize: effectivePageSize }); // This triggers the paginationState watcher
|
|
4247
|
+
}
|
|
4248
|
+
handleRowSelectionState(newValue, oldValue) {
|
|
4249
|
+
if (!this.table) {
|
|
4250
|
+
console.warn('Table is not initialized yet.');
|
|
4251
|
+
return;
|
|
4252
|
+
}
|
|
4253
|
+
// Only update if there is a meaningful change
|
|
4254
|
+
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
|
|
4255
|
+
// Not working
|
|
4256
|
+
/*// Set the rowSelection for the table
|
|
4257
|
+
this.table.setRowSelection(newValue);*/
|
|
4258
|
+
// Manually update the row selection state
|
|
4259
|
+
this.table.options.state.rowSelection = newValue;
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
3936
4262
|
//#endregion WATCHERS
|
|
3937
4263
|
/****************************************************************************/
|
|
3938
4264
|
//#region LIFECYCLE
|
|
@@ -3942,7 +4268,10 @@ const NvDatagrid = class {
|
|
|
3942
4268
|
this.initializeTable();
|
|
3943
4269
|
if (this.enablePagination) {
|
|
3944
4270
|
// Ensure a valid page size
|
|
3945
|
-
|
|
4271
|
+
let effectivePageSize = this.pageSize > 0 ? this.pageSize : 10;
|
|
4272
|
+
if (!this.pageSizes.includes(effectivePageSize) && this.pageSizes) {
|
|
4273
|
+
effectivePageSize = this.pageSizes[0];
|
|
4274
|
+
}
|
|
3946
4275
|
this.paginationState = {
|
|
3947
4276
|
pageIndex: Math.max(0, this.minPageIndex - 1),
|
|
3948
4277
|
pageSize: effectivePageSize,
|
|
@@ -3960,11 +4289,9 @@ const NvDatagrid = class {
|
|
|
3960
4289
|
const rows = !this.table || this.table === undefined || this.parsedData.length === 0
|
|
3961
4290
|
? []
|
|
3962
4291
|
: (_c = (_b = this.table) === null || _b === void 0 ? void 0 : _b.getRowModel()) === null || _c === void 0 ? void 0 : _c.rows;
|
|
3963
|
-
return (index.h(index.Host, { key: '
|
|
4292
|
+
return (index.h(index.Host, { key: '90be657fa9c7f8755391f8d91418399de742ae1f' }, index.h("div", { key: 'f28596438b7c9c22b34789236c5faa644938d1dc', class: "hidden" }, index.h("slot", { key: 'fdc1670cc6bafb5f1efa8c63d41acbfd15659de6' })), index.h("slot", { key: '65afa2282af4842bcb23f8baa592545fe3b74fa3', name: "before" }), this.enableGlobalFilter && this.table && (index.h("div", { key: '8628a23712471690b6a6239a289dd8263aed423c', class: `search-container justify-${this.globalFilterPosition}` }, index.h("nv-fieldtext", { key: '42c56dd6ba426e2045c02b3754fae3562632c49f', value: this.globalFilterSearchTerm, onInput: this.handleGlobalFilteringOnInput, placeholder: "Search all columns..." }))), this.parsedColumns.length === 0 && this.parsedData.length === 0 ? (index.h("div", { class: "no-data" }, this.noColumnsNoDataMessage)) : (index.h("div", null, index.h("table", null, this.parsedColumns.length > 0 && headerGroups.length > 0 && (index.h("thead", null, this.parsedColumns.length > 0 && headerGroups
|
|
3964
4293
|
? headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.map(headerGroup => (index.h("tr", { key: headerGroup.id }, headerGroup.headers.map(header => {
|
|
3965
|
-
return
|
|
3966
|
-
? null
|
|
3967
|
-
: this.flexRender(header.column.columnDef.header, header.getContext())));
|
|
4294
|
+
return this.getHeaderCell(header);
|
|
3968
4295
|
}))))
|
|
3969
4296
|
: null)), index.h("tbody", null, !rows || rows.length === 0 || this.parsedData.length === 0 ? (index.h("tr", null, index.h("td", { colSpan: this.parsedColumns.length || 12, class: "no-data" }, this.noDataMessage))) : (rows.map(row => {
|
|
3970
4297
|
const rowId = row.id;
|
|
@@ -3972,18 +4299,20 @@ const NvDatagrid = class {
|
|
|
3972
4299
|
return (index.h("tr", { key: rowId }, visibleCells.map(cell => {
|
|
3973
4300
|
return (index.h("td", { key: cell.id, "data-row-id": rowId }, this.flexRender(cell.column.columnDef.cell, cell.getContext())));
|
|
3974
4301
|
})));
|
|
3975
|
-
})))
|
|
4302
|
+
}))), this.table && this.enableRowSelection ? (index.h("tfoot", null, index.h("tr", null, index.h("td", { colSpan: 20 }, this.enableRowSelection && this.table ? (index.h("div", null, this.rowSelectionState &&
|
|
4303
|
+
Object.keys(this.rowSelectionState).length > 0 ? (index.h("span", null, Object.keys(this.rowSelectionState).length, " of", ' ', ((_e = (_d = this.table.getPreFilteredRowModel()) === null || _d === void 0 ? void 0 : _d.rows) === null || _e === void 0 ? void 0 : _e.length) || 0, ' ', "Total Rows Selected")) : (index.h("span", null, "No rows selected")))) : null)))) : null), this.getPagination())), index.h("slot", { key: 'e1641d8fd103b0802e1df4f0848f0de921260065', name: "after" })));
|
|
3976
4304
|
}
|
|
3977
4305
|
get el() { return index.getElement(this); }
|
|
3978
4306
|
static get watchers() { return {
|
|
3979
4307
|
"columns": ["parseColumns"],
|
|
3980
|
-
"columnsJson": ["parseJsonColumns"],
|
|
3981
4308
|
"data": ["parseData"],
|
|
3982
|
-
"dataJson": ["parseJsonData"],
|
|
3983
4309
|
"parsedColumns": ["handleParsedChange"],
|
|
3984
4310
|
"parsedData": ["handleParsedChange"],
|
|
3985
4311
|
"globalFilterSearchTerm": ["handleGlobalFilterSearchTerm"],
|
|
3986
|
-
"paginationState": ["handlePaginationState"]
|
|
4312
|
+
"paginationState": ["handlePaginationState"],
|
|
4313
|
+
"sorting": ["handleSorting"],
|
|
4314
|
+
"pageSize": ["handlePageSize"],
|
|
4315
|
+
"rowSelectionState": ["handleRowSelectionState"]
|
|
3987
4316
|
}; }
|
|
3988
4317
|
};
|
|
3989
4318
|
NvDatagrid.style = NvDatagridStyle0;
|