@den4ik92/ng2-smart-table 19.5.44 → 19.5.45

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,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, computed, ChangeDetectionStrategy, Component, signal, effect, inject, ElementRef, Directive, ViewContainerRef, ViewChild, output, viewChild } from '@angular/core';
2
+ import { input, computed, ChangeDetectionStrategy, Component, signal, effect, inject, ElementRef, Directive, untracked, ViewContainerRef, ViewChild, output, viewChild } from '@angular/core';
3
3
  import * as i1 from '@angular/forms';
4
4
  import { UntypedFormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
5
5
  import { distinctUntilChanged, debounceTime, takeUntil, switchMap, take } from 'rxjs/operators';
@@ -352,14 +352,16 @@ class Cell {
352
352
  this.title = '';
353
353
  this.id = '';
354
354
  this.columnClass = column.class;
355
- this.newValue.set(value);
355
+ untracked(() => {
356
+ this.newValue.set(value);
357
+ });
356
358
  this.styles = column.styles;
357
359
  this.title = column.title;
358
360
  this.id = column.id;
359
361
  }
360
362
  getValue() {
361
363
  const prepare = this.column.valuePrepareFunction;
362
- return !prepare ? this.value : prepare.call(null, this.value, this.row.rowData, this);
364
+ return !prepare ? this.value : prepare.call(null, this.value, this.row.rowData(), this);
363
365
  }
364
366
  getNotPrepareValue() {
365
367
  return this.value;
@@ -434,32 +436,30 @@ class Column {
434
436
  }
435
437
 
436
438
  class Row {
437
- constructor(index, rowData, columns) {
439
+ constructor(index, rowDataObj, columnsList) {
438
440
  this.index = index;
439
- this.rowData = rowData;
440
- this.columns = columns;
441
+ this.rowDataObj = rowDataObj;
442
+ this.columnsList = columnsList;
441
443
  this.pending = signal(false);
442
444
  this.isSelected = signal(false);
443
445
  this.isInEditing = signal(false);
444
- this.cells = signal([]);
446
+ this.cells = computed(() => this.columns().map((column) => this.createCell(column, this.rowData())));
447
+ this.rowData = signal({});
448
+ this.columns = signal([]);
445
449
  this.visibleCells = computed(() => this.cells().filter((cell) => !cell.column.hide));
446
- this.process();
450
+ this.rowData.set(rowDataObj);
451
+ this.columns.set(columnsList);
447
452
  }
448
453
  getNewData() {
449
- const values = Object.assign({}, this.rowData);
454
+ const values = Object.assign({}, this.rowData());
450
455
  this.cells().forEach((cell) => (values[cell.column.id] = cell.newValue()));
451
456
  return values;
452
457
  }
453
458
  setData(rowData) {
454
- this.rowData = rowData;
455
- this.process();
459
+ this.rowData.set(rowData);
456
460
  }
457
- process() {
458
- const cells = this.columns.map((column) => this.createCell(column));
459
- this.cells.set(cells);
460
- }
461
- createCell(column) {
462
- const value = typeof this.rowData[column.id] === 'undefined' ? '' : this.rowData[column.id];
461
+ createCell(column, rowData) {
462
+ const value = typeof rowData[column.id] === 'undefined' ? '' : rowData[column.id];
463
463
  return new Cell(value, this, column);
464
464
  }
465
465
  }
@@ -1088,7 +1088,7 @@ class CustomViewComponent {
1088
1088
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.0.3", type: CustomViewComponent, isStandalone: true, selector: "ng2-custom-view-component", inputs: { cell: { classPropertyName: "cell", publicName: "cell", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: `<ng-template
1089
1089
  *ngComponentOutlet="
1090
1090
  cell().column.renderComponent;
1091
- inputs: { rowData: cell().row.rowData, value: cell().getValue() }
1091
+ inputs: { rowData: cell().row.rowData(), value: cell().getValue() }
1092
1092
  "></ng-template>`, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletContent", "ngComponentOutletNgModule", "ngComponentOutletNgModuleFactory"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1093
1093
  }
1094
1094
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: CustomViewComponent, decorators: [{
@@ -1098,7 +1098,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImpor
1098
1098
  template: `<ng-template
1099
1099
  *ngComponentOutlet="
1100
1100
  cell().column.renderComponent;
1101
- inputs: { rowData: cell().row.rowData, value: cell().getValue() }
1101
+ inputs: { rowData: cell().row.rowData(), value: cell().getValue() }
1102
1102
  "></ng-template>`,
1103
1103
  imports: [NgComponentOutlet],
1104
1104
  changeDetection: ChangeDetectionStrategy.OnPush,
@@ -1216,7 +1216,7 @@ class RowActionsComponent {
1216
1216
  if (!actions || !actions.custom) {
1217
1217
  return [];
1218
1218
  }
1219
- const list = actions.custom.filter((action) => !action.hasPermissionFunction ? true : action.hasPermissionFunction(this.row().rowData));
1219
+ const list = actions.custom.filter((action) => !action.hasPermissionFunction ? true : action.hasPermissionFunction(this.row().rowData()));
1220
1220
  return list;
1221
1221
  });
1222
1222
  this.isActionEditActive = computed(() => {
@@ -1228,7 +1228,7 @@ class RowActionsComponent {
1228
1228
  if (!editConfig || !editConfig.hasPermissionFunction) {
1229
1229
  return true;
1230
1230
  }
1231
- return editConfig.hasPermissionFunction(this.row().rowData);
1231
+ return editConfig.hasPermissionFunction(this.row().rowData());
1232
1232
  });
1233
1233
  this.isActionDeleteActive = computed(() => {
1234
1234
  const actions = this.grid().settings().actions;
@@ -1239,7 +1239,7 @@ class RowActionsComponent {
1239
1239
  if (!deleteConfig || !deleteConfig.hasPermissionFunction) {
1240
1240
  return true;
1241
1241
  }
1242
- return deleteConfig.hasPermissionFunction(this.row().rowData);
1242
+ return deleteConfig.hasPermissionFunction(this.row().rowData());
1243
1243
  });
1244
1244
  this.isExternalMode = computed(() => {
1245
1245
  return this.grid().settings().mode === 'external';
@@ -1356,7 +1356,7 @@ class Ng2SmartTableTbodyComponent {
1356
1356
  customActionEmitted(actionName, row) {
1357
1357
  this.customActionEmitter.emit({
1358
1358
  source: this.source(),
1359
- data: row.rowData,
1359
+ data: row.rowData(),
1360
1360
  action: actionName,
1361
1361
  });
1362
1362
  }
@@ -1364,11 +1364,11 @@ class Ng2SmartTableTbodyComponent {
1364
1364
  return item?.id || index;
1365
1365
  }
1366
1366
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: Ng2SmartTableTbodyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1367
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.3", type: Ng2SmartTableTbodyComponent, isStandalone: true, selector: "[ng2-st-tbody]", inputs: { grid: { classPropertyName: "grid", publicName: "grid", isSignal: true, isRequired: true, transformFunction: null }, source: { classPropertyName: "source", publicName: "source", isSignal: true, isRequired: true, transformFunction: null }, rowClassFunction: { classPropertyName: "rowClassFunction", publicName: "rowClassFunction", isSignal: true, isRequired: false, transformFunction: null }, isMobileView: { classPropertyName: "isMobileView", publicName: "isMobileView", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { edit: "edit", editConfirmed: "editConfirmed", editCancel: "editCancel", createConfirmed: "createConfirmed", deleteEmitter: "deleteEmitter", customActionEmitter: "customActionEmitter", userClickedRow: "userClickedRow", multipleSelectRow: "multipleSelectRow" }, ngImport: i0, template: "@if (grid().createFormShown()) {\n <tr\n ng2-st-trow\n class=\"ng2-smart-row\"\n [grid]=\"grid()\"\n [row]=\"grid().getNewRow()\"\n [isCreateRow]=\"true\"\n [source]=\"source()\"\n [isMobileView]=\"isMobileView()\"\n (createConfirmed)=\"createConfirmed.emit()\"></tr>\n}\n@for (row of grid().dataSet.getRows(); track trackByIdOrIndex($index, row)) {\n <tr\n ng2-st-trow\n class=\"ng2-smart-row\"\n [grid]=\"grid()\"\n [source]=\"source()\"\n [row]=\"row\"\n [class]=\"rowClassFunction()(row.rowData)\"\n [isMobileView]=\"isMobileView()\"\n [class.selected]=\"row.isSelected()\"\n (click)=\"rowClicked(row)\"\n (edit)=\"edit.emit(row)\"\n (editConfirmed)=\"editConfirmed.emit(row)\"\n (editCancel)=\"editCancel.emit(row)\"\n (deleteEmitter)=\"deleteEmitter.emit(row)\"\n (customActionEmitter)=\"customActionEmitted($event, row)\"\n (multipleSelectRow)=\"multipleSelectRow.emit($event)\"></tr>\n} @empty {\n <tr>\n <td colspan=\"50\">\n {{ noDataMessage() }}\n </td>\n </tr>\n}\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "component", type: TrowComponent, selector: "[ng2-st-trow]", inputs: ["grid", "source", "row", "isMobileView", "isCreateRow"], outputs: ["edit", "editCancel", "editConfirmed", "deleteEmitter", "createConfirmed", "customActionEmitter", "userClickedRow", "multipleSelectRow"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1367
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.3", type: Ng2SmartTableTbodyComponent, isStandalone: true, selector: "[ng2-st-tbody]", inputs: { grid: { classPropertyName: "grid", publicName: "grid", isSignal: true, isRequired: true, transformFunction: null }, source: { classPropertyName: "source", publicName: "source", isSignal: true, isRequired: true, transformFunction: null }, rowClassFunction: { classPropertyName: "rowClassFunction", publicName: "rowClassFunction", isSignal: true, isRequired: false, transformFunction: null }, isMobileView: { classPropertyName: "isMobileView", publicName: "isMobileView", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { edit: "edit", editConfirmed: "editConfirmed", editCancel: "editCancel", createConfirmed: "createConfirmed", deleteEmitter: "deleteEmitter", customActionEmitter: "customActionEmitter", userClickedRow: "userClickedRow", multipleSelectRow: "multipleSelectRow" }, ngImport: i0, template: "@if (grid().createFormShown()) {\n <tr\n ng2-st-trow\n class=\"ng2-smart-row\"\n [grid]=\"grid()\"\n [row]=\"grid().getNewRow()\"\n [isCreateRow]=\"true\"\n [source]=\"source()\"\n [isMobileView]=\"isMobileView()\"\n (createConfirmed)=\"createConfirmed.emit()\"></tr>\n}\n@for (row of grid().dataSet.getRows(); track trackByIdOrIndex($index, row)) {\n <tr\n ng2-st-trow\n class=\"ng2-smart-row\"\n [grid]=\"grid()\"\n [source]=\"source()\"\n [row]=\"row\"\n [class]=\"rowClassFunction()(row.rowData())\"\n [isMobileView]=\"isMobileView()\"\n [class.selected]=\"row.isSelected()\"\n (click)=\"rowClicked(row)\"\n (edit)=\"edit.emit(row)\"\n (editConfirmed)=\"editConfirmed.emit(row)\"\n (editCancel)=\"editCancel.emit(row)\"\n (deleteEmitter)=\"deleteEmitter.emit(row)\"\n (customActionEmitter)=\"customActionEmitted($event, row)\"\n (multipleSelectRow)=\"multipleSelectRow.emit($event)\"></tr>\n} @empty {\n <tr>\n <td colspan=\"50\">\n {{ noDataMessage() }}\n </td>\n </tr>\n}\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "component", type: TrowComponent, selector: "[ng2-st-trow]", inputs: ["grid", "source", "row", "isMobileView", "isCreateRow"], outputs: ["edit", "editCancel", "editConfirmed", "deleteEmitter", "createConfirmed", "customActionEmitter", "userClickedRow", "multipleSelectRow"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1368
1368
  }
1369
1369
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: Ng2SmartTableTbodyComponent, decorators: [{
1370
1370
  type: Component,
1371
- args: [{ selector: '[ng2-st-tbody]', imports: [FormsModule, TrowComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (grid().createFormShown()) {\n <tr\n ng2-st-trow\n class=\"ng2-smart-row\"\n [grid]=\"grid()\"\n [row]=\"grid().getNewRow()\"\n [isCreateRow]=\"true\"\n [source]=\"source()\"\n [isMobileView]=\"isMobileView()\"\n (createConfirmed)=\"createConfirmed.emit()\"></tr>\n}\n@for (row of grid().dataSet.getRows(); track trackByIdOrIndex($index, row)) {\n <tr\n ng2-st-trow\n class=\"ng2-smart-row\"\n [grid]=\"grid()\"\n [source]=\"source()\"\n [row]=\"row\"\n [class]=\"rowClassFunction()(row.rowData)\"\n [isMobileView]=\"isMobileView()\"\n [class.selected]=\"row.isSelected()\"\n (click)=\"rowClicked(row)\"\n (edit)=\"edit.emit(row)\"\n (editConfirmed)=\"editConfirmed.emit(row)\"\n (editCancel)=\"editCancel.emit(row)\"\n (deleteEmitter)=\"deleteEmitter.emit(row)\"\n (customActionEmitter)=\"customActionEmitted($event, row)\"\n (multipleSelectRow)=\"multipleSelectRow.emit($event)\"></tr>\n} @empty {\n <tr>\n <td colspan=\"50\">\n {{ noDataMessage() }}\n </td>\n </tr>\n}\n" }]
1371
+ args: [{ selector: '[ng2-st-tbody]', imports: [FormsModule, TrowComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (grid().createFormShown()) {\n <tr\n ng2-st-trow\n class=\"ng2-smart-row\"\n [grid]=\"grid()\"\n [row]=\"grid().getNewRow()\"\n [isCreateRow]=\"true\"\n [source]=\"source()\"\n [isMobileView]=\"isMobileView()\"\n (createConfirmed)=\"createConfirmed.emit()\"></tr>\n}\n@for (row of grid().dataSet.getRows(); track trackByIdOrIndex($index, row)) {\n <tr\n ng2-st-trow\n class=\"ng2-smart-row\"\n [grid]=\"grid()\"\n [source]=\"source()\"\n [row]=\"row\"\n [class]=\"rowClassFunction()(row.rowData())\"\n [isMobileView]=\"isMobileView()\"\n [class.selected]=\"row.isSelected()\"\n (click)=\"rowClicked(row)\"\n (edit)=\"edit.emit(row)\"\n (editConfirmed)=\"editConfirmed.emit(row)\"\n (editCancel)=\"editCancel.emit(row)\"\n (deleteEmitter)=\"deleteEmitter.emit(row)\"\n (customActionEmitter)=\"customActionEmitted($event, row)\"\n (multipleSelectRow)=\"multipleSelectRow.emit($event)\"></tr>\n} @empty {\n <tr>\n <td colspan=\"50\">\n {{ noDataMessage() }}\n </td>\n </tr>\n}\n" }]
1372
1372
  }] });
1373
1373
 
1374
1374
  class AddButtonComponent {
@@ -2097,7 +2097,7 @@ class DataSet {
2097
2097
  this.createRows();
2098
2098
  }
2099
2099
  findRowByData(data) {
2100
- return this.rows().find((row) => isObjectsIdentical(row.rowData, data));
2100
+ return this.rows().find((row) => isObjectsIdentical(row.rowData(), data));
2101
2101
  }
2102
2102
  setSelectAll(state) {
2103
2103
  this.rows().forEach((row) => {
@@ -2154,15 +2154,17 @@ class DataSet {
2154
2154
  }
2155
2155
  storeSelectedRow(row) {
2156
2156
  if (row.isSelected()) {
2157
- if (this.isSelectedHasRow(row.rowData)) {
2157
+ if (this.isSelectedHasRow(row.rowData())) {
2158
2158
  //check if row already in selected array to prevent duplicate
2159
2159
  return;
2160
2160
  }
2161
- this.selectedRowsData.push(row.rowData);
2161
+ this.selectedRowsData.push(row.rowData());
2162
2162
  }
2163
2163
  else {
2164
2164
  const index = this.selectedRowsData.findIndex((rowData) => isObjectsIdentical(rowData, row));
2165
- this.selectedRowsData.splice(index, 1);
2165
+ if (index !== -1) {
2166
+ this.selectedRowsData.splice(index, 1);
2167
+ }
2166
2168
  }
2167
2169
  }
2168
2170
  }
@@ -2256,7 +2258,7 @@ class Grid {
2256
2258
  .then((newData) => {
2257
2259
  row.pending.set(false);
2258
2260
  newData = newData || row.getNewData();
2259
- this.source.update(row.rowData, newData).then(() => {
2261
+ this.source.update(row.rowData(), newData).then(() => {
2260
2262
  row.isInEditing.set(false);
2261
2263
  });
2262
2264
  })
@@ -2266,7 +2268,7 @@ class Grid {
2266
2268
  });
2267
2269
  if (this.getSetting('edit.confirmSave', false)) {
2268
2270
  confirmEmitter.emit({
2269
- data: row.rowData,
2271
+ data: row.rowData(),
2270
2272
  newData: row.getNewData(),
2271
2273
  source: this.source,
2272
2274
  confirm: deferred,
@@ -2283,7 +2285,7 @@ class Grid {
2283
2285
  deferred.promise
2284
2286
  .then(() => {
2285
2287
  row.pending.set(false);
2286
- this.source.remove(row.rowData);
2288
+ this.source.remove(row.rowData());
2287
2289
  })
2288
2290
  .catch(() => {
2289
2291
  row.pending.set(false);
@@ -2291,7 +2293,7 @@ class Grid {
2291
2293
  });
2292
2294
  if (this.getSetting('delete.confirmDelete', true)) {
2293
2295
  confirmEmitter.emit({
2294
- data: row.rowData,
2296
+ data: row.rowData(),
2295
2297
  source: this.source,
2296
2298
  confirm: deferred,
2297
2299
  });
@@ -2518,7 +2520,7 @@ class Ng2SmartTableComponent {
2518
2520
  }
2519
2521
  emitUserRowClicked(row) {
2520
2522
  this.rowClicked.emit({
2521
- data: row ? row.rowData : null,
2523
+ data: row ? row.rowData() : null,
2522
2524
  source: this.source(),
2523
2525
  });
2524
2526
  }
@@ -2528,7 +2530,7 @@ class Ng2SmartTableComponent {
2528
2530
  editEmitted(row) {
2529
2531
  if (this.isExternalMode()) {
2530
2532
  this.edit.emit({
2531
- data: row.rowData,
2533
+ data: row.rowData(),
2532
2534
  source: this.source(),
2533
2535
  });
2534
2536
  return;
@@ -2539,7 +2541,7 @@ class Ng2SmartTableComponent {
2539
2541
  this.grid.save(row, this.editConfirm);
2540
2542
  }
2541
2543
  editCanceled(row) {
2542
- this.editCancel.emit({ data: row.rowData, source: this.source() });
2544
+ this.editCancel.emit({ data: row.rowData(), source: this.source() });
2543
2545
  }
2544
2546
  createEmitted() {
2545
2547
  if (this.isExternalMode()) {
@@ -2555,7 +2557,7 @@ class Ng2SmartTableComponent {
2555
2557
  deleEmitted(row) {
2556
2558
  if (this.isExternalMode()) {
2557
2559
  this.deleteEmitter.emit({
2558
- data: row.rowData,
2560
+ data: row.rowData(),
2559
2561
  source: this.source(),
2560
2562
  });
2561
2563
  }
@@ -2569,7 +2571,7 @@ class Ng2SmartTableComponent {
2569
2571
  }
2570
2572
  emitUserSelectRow(row) {
2571
2573
  this.multiRowSelect.emit({
2572
- data: row ? row.rowData : null,
2574
+ data: row ? row.rowData() : null,
2573
2575
  isSelected: row ? row.isSelected() : false,
2574
2576
  source: this.source(),
2575
2577
  selected: this.grid.dataSet.getSelectedRowsData(),