@den4ik92/ng2-smart-table 19.5.44 → 19.5.46

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();
456
- }
457
- process() {
458
- const cells = this.columns.map((column) => this.createCell(column));
459
- this.cells.set(cells);
459
+ this.rowData.set(rowData);
460
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
  }
@@ -513,16 +513,19 @@ class DataSource {
513
513
  }
514
514
  async appendMany(elements) {
515
515
  this.data.update((old) => [...old, ...elements]);
516
+ this.updateTotal(elements.length);
516
517
  this.emitOnChanged({ action: SmartTableOnChangedEventName.appendMany, newItems: elements });
517
518
  return Promise.resolve(true);
518
519
  }
519
520
  async add(element) {
520
521
  this.data.update((old) => [...old, element]);
522
+ this.updateTotal(1);
521
523
  this.emitOnChanged({ action: SmartTableOnChangedEventName.add, newItems: [element] });
522
524
  return Promise.resolve(true);
523
525
  }
524
526
  async remove(element) {
525
527
  this.data.update((old) => old.filter((el) => !isObjectsIdentical(el, element)));
528
+ this.updateTotal(-1);
526
529
  this.emitOnChanged({ action: SmartTableOnChangedEventName.remove, item: element }, this.data());
527
530
  return Promise.resolve(true);
528
531
  }
@@ -603,6 +606,13 @@ class DataSource {
603
606
  };
604
607
  this.onChangedSource.next(actionData);
605
608
  }
609
+ /**
610
+ * @param difference number to plus total
611
+ * @example -2 or 2
612
+ */
613
+ updateTotal(difference) {
614
+ this.pagingConf.update((old) => ({ ...old, total: old.total + difference }));
615
+ }
606
616
  }
607
617
 
608
618
  function exactMatch(value, search) {
@@ -1088,7 +1098,7 @@ class CustomViewComponent {
1088
1098
  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
1099
  *ngComponentOutlet="
1090
1100
  cell().column.renderComponent;
1091
- inputs: { rowData: cell().row.rowData, value: cell().getValue() }
1101
+ inputs: { rowData: cell().row.rowData(), value: cell().getValue() }
1092
1102
  "></ng-template>`, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletContent", "ngComponentOutletNgModule", "ngComponentOutletNgModuleFactory"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1093
1103
  }
1094
1104
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: CustomViewComponent, decorators: [{
@@ -1098,7 +1108,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImpor
1098
1108
  template: `<ng-template
1099
1109
  *ngComponentOutlet="
1100
1110
  cell().column.renderComponent;
1101
- inputs: { rowData: cell().row.rowData, value: cell().getValue() }
1111
+ inputs: { rowData: cell().row.rowData(), value: cell().getValue() }
1102
1112
  "></ng-template>`,
1103
1113
  imports: [NgComponentOutlet],
1104
1114
  changeDetection: ChangeDetectionStrategy.OnPush,
@@ -1216,7 +1226,7 @@ class RowActionsComponent {
1216
1226
  if (!actions || !actions.custom) {
1217
1227
  return [];
1218
1228
  }
1219
- const list = actions.custom.filter((action) => !action.hasPermissionFunction ? true : action.hasPermissionFunction(this.row().rowData));
1229
+ const list = actions.custom.filter((action) => !action.hasPermissionFunction ? true : action.hasPermissionFunction(this.row().rowData()));
1220
1230
  return list;
1221
1231
  });
1222
1232
  this.isActionEditActive = computed(() => {
@@ -1228,7 +1238,7 @@ class RowActionsComponent {
1228
1238
  if (!editConfig || !editConfig.hasPermissionFunction) {
1229
1239
  return true;
1230
1240
  }
1231
- return editConfig.hasPermissionFunction(this.row().rowData);
1241
+ return editConfig.hasPermissionFunction(this.row().rowData());
1232
1242
  });
1233
1243
  this.isActionDeleteActive = computed(() => {
1234
1244
  const actions = this.grid().settings().actions;
@@ -1239,7 +1249,7 @@ class RowActionsComponent {
1239
1249
  if (!deleteConfig || !deleteConfig.hasPermissionFunction) {
1240
1250
  return true;
1241
1251
  }
1242
- return deleteConfig.hasPermissionFunction(this.row().rowData);
1252
+ return deleteConfig.hasPermissionFunction(this.row().rowData());
1243
1253
  });
1244
1254
  this.isExternalMode = computed(() => {
1245
1255
  return this.grid().settings().mode === 'external';
@@ -1356,7 +1366,7 @@ class Ng2SmartTableTbodyComponent {
1356
1366
  customActionEmitted(actionName, row) {
1357
1367
  this.customActionEmitter.emit({
1358
1368
  source: this.source(),
1359
- data: row.rowData,
1369
+ data: row.rowData(),
1360
1370
  action: actionName,
1361
1371
  });
1362
1372
  }
@@ -1364,11 +1374,11 @@ class Ng2SmartTableTbodyComponent {
1364
1374
  return item?.id || index;
1365
1375
  }
1366
1376
  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 }); }
1377
+ 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
1378
  }
1369
1379
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: Ng2SmartTableTbodyComponent, decorators: [{
1370
1380
  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" }]
1381
+ 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
1382
  }] });
1373
1383
 
1374
1384
  class AddButtonComponent {
@@ -2097,7 +2107,7 @@ class DataSet {
2097
2107
  this.createRows();
2098
2108
  }
2099
2109
  findRowByData(data) {
2100
- return this.rows().find((row) => isObjectsIdentical(row.rowData, data));
2110
+ return this.rows().find((row) => isObjectsIdentical(row.rowData(), data));
2101
2111
  }
2102
2112
  setSelectAll(state) {
2103
2113
  this.rows().forEach((row) => {
@@ -2154,15 +2164,17 @@ class DataSet {
2154
2164
  }
2155
2165
  storeSelectedRow(row) {
2156
2166
  if (row.isSelected()) {
2157
- if (this.isSelectedHasRow(row.rowData)) {
2167
+ if (this.isSelectedHasRow(row.rowData())) {
2158
2168
  //check if row already in selected array to prevent duplicate
2159
2169
  return;
2160
2170
  }
2161
- this.selectedRowsData.push(row.rowData);
2171
+ this.selectedRowsData.push(row.rowData());
2162
2172
  }
2163
2173
  else {
2164
2174
  const index = this.selectedRowsData.findIndex((rowData) => isObjectsIdentical(rowData, row));
2165
- this.selectedRowsData.splice(index, 1);
2175
+ if (index !== -1) {
2176
+ this.selectedRowsData.splice(index, 1);
2177
+ }
2166
2178
  }
2167
2179
  }
2168
2180
  }
@@ -2256,7 +2268,7 @@ class Grid {
2256
2268
  .then((newData) => {
2257
2269
  row.pending.set(false);
2258
2270
  newData = newData || row.getNewData();
2259
- this.source.update(row.rowData, newData).then(() => {
2271
+ this.source.update(row.rowData(), newData).then(() => {
2260
2272
  row.isInEditing.set(false);
2261
2273
  });
2262
2274
  })
@@ -2266,7 +2278,7 @@ class Grid {
2266
2278
  });
2267
2279
  if (this.getSetting('edit.confirmSave', false)) {
2268
2280
  confirmEmitter.emit({
2269
- data: row.rowData,
2281
+ data: row.rowData(),
2270
2282
  newData: row.getNewData(),
2271
2283
  source: this.source,
2272
2284
  confirm: deferred,
@@ -2283,7 +2295,7 @@ class Grid {
2283
2295
  deferred.promise
2284
2296
  .then(() => {
2285
2297
  row.pending.set(false);
2286
- this.source.remove(row.rowData);
2298
+ this.source.remove(row.rowData());
2287
2299
  })
2288
2300
  .catch(() => {
2289
2301
  row.pending.set(false);
@@ -2291,7 +2303,7 @@ class Grid {
2291
2303
  });
2292
2304
  if (this.getSetting('delete.confirmDelete', true)) {
2293
2305
  confirmEmitter.emit({
2294
- data: row.rowData,
2306
+ data: row.rowData(),
2295
2307
  source: this.source,
2296
2308
  confirm: deferred,
2297
2309
  });
@@ -2518,7 +2530,7 @@ class Ng2SmartTableComponent {
2518
2530
  }
2519
2531
  emitUserRowClicked(row) {
2520
2532
  this.rowClicked.emit({
2521
- data: row ? row.rowData : null,
2533
+ data: row ? row.rowData() : null,
2522
2534
  source: this.source(),
2523
2535
  });
2524
2536
  }
@@ -2528,7 +2540,7 @@ class Ng2SmartTableComponent {
2528
2540
  editEmitted(row) {
2529
2541
  if (this.isExternalMode()) {
2530
2542
  this.edit.emit({
2531
- data: row.rowData,
2543
+ data: row.rowData(),
2532
2544
  source: this.source(),
2533
2545
  });
2534
2546
  return;
@@ -2539,7 +2551,7 @@ class Ng2SmartTableComponent {
2539
2551
  this.grid.save(row, this.editConfirm);
2540
2552
  }
2541
2553
  editCanceled(row) {
2542
- this.editCancel.emit({ data: row.rowData, source: this.source() });
2554
+ this.editCancel.emit({ data: row.rowData(), source: this.source() });
2543
2555
  }
2544
2556
  createEmitted() {
2545
2557
  if (this.isExternalMode()) {
@@ -2555,7 +2567,7 @@ class Ng2SmartTableComponent {
2555
2567
  deleEmitted(row) {
2556
2568
  if (this.isExternalMode()) {
2557
2569
  this.deleteEmitter.emit({
2558
- data: row.rowData,
2570
+ data: row.rowData(),
2559
2571
  source: this.source(),
2560
2572
  });
2561
2573
  }
@@ -2569,7 +2581,7 @@ class Ng2SmartTableComponent {
2569
2581
  }
2570
2582
  emitUserSelectRow(row) {
2571
2583
  this.multiRowSelect.emit({
2572
- data: row ? row.rowData : null,
2584
+ data: row ? row.rowData() : null,
2573
2585
  isSelected: row ? row.isSelected() : false,
2574
2586
  source: this.source(),
2575
2587
  selected: this.grid.dataSet.getSelectedRowsData(),