@den4ik92/ng2-smart-table 1.0.9 → 2.0.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.
Files changed (87) hide show
  1. package/esm2020/lib/components/cell/cell-edit-mode/custom-edit.component.mjs +4 -3
  2. package/esm2020/lib/components/cell/cell-edit-mode/default-edit.component.mjs +11 -8
  3. package/esm2020/lib/components/cell/cell-edit-mode/edit-cell-default.mjs +1 -1
  4. package/esm2020/lib/components/cell/cell-edit-mode/edit-cell.component.mjs +6 -2
  5. package/esm2020/lib/components/cell/cell-editors/checkbox-editor.component.mjs +6 -5
  6. package/esm2020/lib/components/cell/cell-editors/default-editor.mjs +2 -1
  7. package/esm2020/lib/components/cell/cell-view-mode/custom-view.component.mjs +1 -6
  8. package/esm2020/lib/components/cell/cell-view-mode/view-cell.component.mjs +1 -1
  9. package/esm2020/lib/components/cell/cell.component.mjs +1 -1
  10. package/esm2020/lib/components/cell/cell.module.mjs +1 -5
  11. package/esm2020/lib/components/filter/custom-filter.component.mjs +15 -16
  12. package/esm2020/lib/components/filter/default-filter.component.mjs +7 -22
  13. package/esm2020/lib/components/filter/filter-default.mjs +6 -4
  14. package/esm2020/lib/components/filter/filter-types/default-filter.mjs +3 -1
  15. package/esm2020/lib/components/filter/filter-types/input-filter.component.mjs +2 -2
  16. package/esm2020/lib/components/filter/filter-types/select-filter.component.mjs +6 -4
  17. package/esm2020/lib/components/filter/filter.component.mjs +4 -8
  18. package/esm2020/lib/components/filter/filter.module.mjs +1 -5
  19. package/esm2020/lib/components/pager/pager.component.mjs +21 -18
  20. package/esm2020/lib/components/tbody/cells/create-cancel.component.mjs +7 -3
  21. package/esm2020/lib/components/tbody/cells/custom.component.mjs +2 -1
  22. package/esm2020/lib/components/tbody/cells/edit-delete.component.mjs +6 -2
  23. package/esm2020/lib/components/tbody/tbody.component.mjs +17 -7
  24. package/esm2020/lib/components/thead/cells/actions-title.component.mjs +2 -1
  25. package/esm2020/lib/components/thead/cells/actions.component.mjs +3 -1
  26. package/esm2020/lib/components/thead/cells/add-button.component.mjs +4 -2
  27. package/esm2020/lib/components/thead/cells/checkbox-select-all.component.mjs +2 -2
  28. package/esm2020/lib/components/thead/cells/column-title.component.mjs +2 -2
  29. package/esm2020/lib/components/thead/cells/title/title.component.mjs +6 -7
  30. package/esm2020/lib/components/thead/rows/thead-filters-row.component.mjs +7 -3
  31. package/esm2020/lib/components/thead/rows/thead-form-row.component.mjs +6 -2
  32. package/esm2020/lib/components/thead/rows/thead-titles-row.component.mjs +5 -2
  33. package/esm2020/lib/components/thead/thead.component.mjs +6 -4
  34. package/esm2020/lib/lib/data-set/column.mjs +37 -38
  35. package/esm2020/lib/lib/data-set/data-set.mjs +1 -1
  36. package/esm2020/lib/lib/data-set/row.mjs +1 -1
  37. package/esm2020/lib/lib/data-source/data-source.mjs +18 -28
  38. package/esm2020/lib/lib/data-source/local/local.data-source.mjs +53 -26
  39. package/esm2020/lib/lib/grid.mjs +19 -32
  40. package/esm2020/lib/lib/helpers.mjs +2 -2
  41. package/esm2020/lib/lib/interfaces/smart-table.models.mjs +1 -1
  42. package/esm2020/lib/ng2-smart-table.component.mjs +14 -18
  43. package/esm2020/public-api.mjs +1 -2
  44. package/fesm2015/den4ik92-ng2-smart-table.mjs +301 -480
  45. package/fesm2015/den4ik92-ng2-smart-table.mjs.map +1 -1
  46. package/fesm2020/den4ik92-ng2-smart-table.mjs +1627 -1811
  47. package/fesm2020/den4ik92-ng2-smart-table.mjs.map +1 -1
  48. package/lib/components/cell/cell-edit-mode/default-edit.component.d.ts +2 -1
  49. package/lib/components/cell/cell-edit-mode/edit-cell.component.d.ts +2 -1
  50. package/lib/components/cell/cell-view-mode/custom-view.component.d.ts +0 -1
  51. package/lib/components/cell/cell.module.d.ts +8 -9
  52. package/lib/components/filter/custom-filter.component.d.ts +1 -2
  53. package/lib/components/filter/default-filter.component.d.ts +1 -2
  54. package/lib/components/filter/filter-default.d.ts +4 -4
  55. package/lib/components/filter/filter-types/default-filter.d.ts +1 -1
  56. package/lib/components/filter/filter.component.d.ts +1 -2
  57. package/lib/components/filter/filter.module.d.ts +5 -6
  58. package/lib/components/pager/pager.component.d.ts +8 -8
  59. package/lib/components/tbody/cells/custom.component.d.ts +2 -1
  60. package/lib/components/tbody/cells/edit-delete.component.d.ts +2 -2
  61. package/lib/components/tbody/tbody.component.d.ts +5 -5
  62. package/lib/components/thead/cells/add-button.component.d.ts +2 -2
  63. package/lib/components/thead/cells/checkbox-select-all.component.d.ts +2 -2
  64. package/lib/components/thead/cells/column-title.component.d.ts +2 -2
  65. package/lib/components/thead/cells/title/title.component.d.ts +5 -4
  66. package/lib/components/thead/rows/thead-filters-row.component.d.ts +2 -2
  67. package/lib/components/thead/rows/thead-titles-row.component.d.ts +2 -2
  68. package/lib/components/thead/thead.component.d.ts +2 -2
  69. package/lib/lib/data-set/column.d.ts +16 -26
  70. package/lib/lib/data-set/data-set.d.ts +4 -4
  71. package/lib/lib/data-set/row.d.ts +3 -3
  72. package/lib/lib/data-source/data-source.d.ts +13 -13
  73. package/lib/lib/data-source/local/local.data-source.d.ts +4 -4
  74. package/lib/lib/grid.d.ts +8 -10
  75. package/lib/lib/helpers.d.ts +1 -1
  76. package/lib/lib/interfaces/smart-table.models.d.ts +26 -29
  77. package/lib/ng2-smart-table.component.d.ts +4 -4
  78. package/package.json +1 -1
  79. package/public-api.d.ts +0 -1
  80. package/esm2020/lib/components/cell/cell-editors/completer-editor.component.mjs +0 -46
  81. package/esm2020/lib/components/filter/filter-types/completer-filter.component.mjs +0 -61
  82. package/esm2020/lib/lib/data-source/server/server-source.conf.mjs +0 -20
  83. package/esm2020/lib/lib/data-source/server/server.data-source.mjs +0 -93
  84. package/lib/components/cell/cell-editors/completer-editor.component.d.ts +0 -13
  85. package/lib/components/filter/filter-types/completer-filter.component.d.ts +0 -12
  86. package/lib/lib/data-source/server/server-source.conf.d.ts +0 -27
  87. package/lib/lib/data-source/server/server.data-source.d.ts +0 -30
@@ -5,8 +5,7 @@ import { CommonModule } from '@angular/common';
5
5
  import * as i2 from '@angular/forms';
6
6
  import { FormsModule, UntypedFormControl, NgControl, ReactiveFormsModule } from '@angular/forms';
7
7
  import { Subject } from 'rxjs';
8
- import { debounceTime, distinctUntilChanged, skip, map } from 'rxjs/operators';
9
- import { HttpParams } from '@angular/common/http';
8
+ import { debounceTime, distinctUntilChanged, skip } from 'rxjs/operators';
10
9
 
11
10
  /**
12
11
  * Extending object that entered in first argument.
@@ -76,7 +75,7 @@ class Deferred {
76
75
  }
77
76
  }
78
77
  // getDeepFromObject({result: {data: 1}}, 'result.data', 2); // returns 1
79
- function getDeepFromObject(object = {}, name, defaultValue) {
78
+ function getDeepFromObject(object = {}, name, defaultValue = null) {
80
79
  const keys = name.split('.');
81
80
  // clone the object
82
81
  let level = deepExtend({}, object);
@@ -184,7 +183,7 @@ class Column {
184
183
  this.settings = settings;
185
184
  this.dataSet = dataSet;
186
185
  this.title = '';
187
- this.type = '';
186
+ this.type = 'text';
188
187
  this.class = '';
189
188
  this.width = '';
190
189
  this.hide = false;
@@ -192,16 +191,12 @@ class Column {
192
191
  this.isEditable = true;
193
192
  this.isAddable = true;
194
193
  this.isFilterable = false;
195
- this.sortDirection = '';
196
- this.defaultSortDirection = '';
197
- this.editor = { type: '', config: {}, component: null };
198
- this.filter = { type: '', config: {}, component: null };
199
- this.renderComponent = null;
194
+ this.sortDirection = 'asc';
195
+ this.defaultSortDirection = false;
196
+ this.editor = false;
197
+ this.filter = false;
200
198
  this.process();
201
199
  }
202
- getOnComponentInitFunction() {
203
- return this.onComponentInitFunction;
204
- }
205
200
  getCompareFunction() {
206
201
  return this.compareFunction;
207
202
  }
@@ -212,44 +207,47 @@ class Column {
212
207
  return this.filterFunction;
213
208
  }
214
209
  getConfig() {
215
- return this.editor && this.editor.config;
210
+ if (this.editor && (this.editor.type === 'checkbox' || this.editor.type === 'custom' || this.editor.type === 'list')) {
211
+ return this.editor?.config;
212
+ }
213
+ return false;
216
214
  }
217
215
  getFilterType() {
218
216
  return this.filter && this.filter.type;
219
217
  }
220
218
  getFilterConfig() {
221
- return this.filter && this.filter.config;
219
+ if (this.filter && (this.filter.type === 'checkbox' || this.filter.type === 'custom' || this.filter.type === 'list')) {
220
+ return this.filter?.config;
221
+ }
222
+ return false;
222
223
  }
223
224
  process() {
224
- this.title = this.settings['title'];
225
- this.class = this.settings['class'];
226
- this.width = this.settings['width'];
227
- this.hide = !!this.settings['hide'];
228
- this.type = this.prepareType();
229
- this.editor = this.settings['editor'];
230
- this.filter = this.settings['filter'];
231
- this.renderComponent = this.settings['renderComponent'];
232
- this.isFilterable = typeof this.settings['filter'] === 'undefined' ? true : !!this.settings['filter'];
233
- this.defaultSortDirection = ['asc', 'desc']
234
- .indexOf(this.settings['sortDirection']) !== -1 ? this.settings['sortDirection'] : '';
235
- this.isSortable = typeof this.settings['sort'] === 'undefined' ? true : !!this.settings['sort'];
236
- this.isEditable = typeof this.settings['editable'] === 'undefined' ? true : !!this.settings['editable'];
237
- this.isAddable = typeof this.settings['addable'] === 'undefined' ? true : !!this.settings['addable'];
225
+ this.title = this.settings.title;
226
+ this.class = this.settings.class || '';
227
+ this.width = this.settings.width || '';
228
+ this.hide = !!this.settings.hide;
229
+ this.type = this.settings.type;
230
+ if (this.settings?.editor) {
231
+ this.editor = this.settings.editor;
232
+ }
233
+ if (this.settings?.filter) {
234
+ this.filter = this.settings.filter;
235
+ }
236
+ if (this.settings.type === 'custom' && this.settings.renderComponent) {
237
+ this.renderComponent = this.settings.renderComponent;
238
+ }
239
+ this.isFilterable = typeof this.settings.filter === 'undefined' ? true : !!this.settings['filter'];
240
+ this.defaultSortDirection = this.settings?.sortDirection || false;
241
+ this.isSortable = typeof this.settings.sort === 'undefined' ? true : this.settings.sort;
242
+ this.isEditable = typeof this.settings.editable === 'undefined' ? true : this.settings.editable;
243
+ this.isAddable = typeof this.settings.addable === 'undefined' ? true : this.settings.addable;
238
244
  this.sortDirection = this.prepareSortDirection();
239
- this.compareFunction = this.settings['compareFunction'];
240
- this.valuePrepareFunction = this.settings['valuePrepareFunction'];
241
- this.filterFunction = this.settings['filterFunction'];
242
- this.onComponentInitFunction = this.settings['onComponentInitFunction'];
243
- }
244
- prepareType() {
245
- return this.settings['type'] || this.determineType();
245
+ this.compareFunction = this.settings.compareFunction;
246
+ this.valuePrepareFunction = this.settings.valuePrepareFunction;
247
+ this.filterFunction = this.settings.filterFunction;
246
248
  }
247
249
  prepareSortDirection() {
248
- return this.settings['sort'] === 'desc' ? 'desc' : 'asc';
249
- }
250
- determineType() {
251
- // TODO: determine type by data
252
- return 'text';
250
+ return this.defaultSortDirection === 'desc' ? 'desc' : 'asc';
253
251
  }
254
252
  }
255
253
 
@@ -372,7 +370,7 @@ class Grid {
372
370
  return position == this.getSetting('actions.position');
373
371
  }
374
372
  isActionsVisible() {
375
- return this.getSetting('actions.add') || this.getSetting('actions.edit') || this.getSetting('actions.delete') || this.getSetting('actions.custom').length;
373
+ return this.getSetting('actions.add', false) || this.getSetting('actions.edit', false) || this.getSetting('actions.delete', false) || !!this.getSetting('actions.custom', [])?.length;
376
374
  }
377
375
  isMultiSelectVisible() {
378
376
  return this.getSetting('selectMode') === 'multi';
@@ -396,7 +394,9 @@ class Grid {
396
394
  this.sourceOnChangedSubscription = this.source.onChanged().subscribe((changes) => this.processDataChange(changes));
397
395
  this.sourceOnUpdatedSubscription = this.source.onUpdated().subscribe((data) => {
398
396
  const changedRow = this.dataSet.findRowByData(data);
399
- changedRow.setData(data);
397
+ if (changedRow) {
398
+ changedRow.setData(data);
399
+ }
400
400
  });
401
401
  }
402
402
  getSetting(name, defaultValue) {
@@ -516,26 +516,26 @@ class Grid {
516
516
  return false;
517
517
  }
518
518
  prepareSource(source) {
519
- const initialSource = this.getInitialSort();
520
- if (initialSource && initialSource['field'] && initialSource['direction']) {
521
- source.setSort([initialSource], false);
519
+ const initialSort = this.getInitialSort();
520
+ if (initialSort) {
521
+ source.setSort([initialSort], false);
522
522
  }
523
523
  if (this.getSetting('pager.display') === true) {
524
- source.setPaging(this.getPageToSelect(source), this.getSetting('pager.perPage'), false);
524
+ source.setPaging(1, this.getSetting('pager.perPage'), false);
525
525
  }
526
526
  source.refresh();
527
527
  return source;
528
528
  }
529
529
  getInitialSort() {
530
- const sortConf = {};
531
- this.getColumns().forEach((column) => {
532
- if (column.isSortable && column.defaultSortDirection) {
533
- sortConf['field'] = column.id;
534
- sortConf['direction'] = column.defaultSortDirection;
535
- sortConf['compare'] = column.getCompareFunction();
536
- }
537
- });
538
- return sortConf;
530
+ const defaultSortColumn = this.getColumns().find((column) => column.isSortable && column.defaultSortDirection);
531
+ if (!defaultSortColumn) {
532
+ return false;
533
+ }
534
+ return {
535
+ field: defaultSortColumn.id,
536
+ direction: defaultSortColumn.defaultSortDirection || 'asc',
537
+ compare: defaultSortColumn.getCompareFunction(),
538
+ };
539
539
  }
540
540
  getSelectedRowsData() {
541
541
  return this.dataSet.getRows();
@@ -549,21 +549,6 @@ class Grid {
549
549
  getLastRow() {
550
550
  return this.dataSet.getLastRow();
551
551
  }
552
- getSelectionInfo() {
553
- const switchPageToSelectedRowPage = this.getSetting('switchPageToSelectedRowPage');
554
- const selectedRowIndex = Number(this.getSetting('selectedRowIndex', 0)) || 0;
555
- const { perPage, page } = this.getSetting('pager');
556
- return { perPage, page, selectedRowIndex, switchPageToSelectedRowPage };
557
- }
558
- getPageToSelect(source) {
559
- const { switchPageToSelectedRowPage, selectedRowIndex, perPage, page } = this.getSelectionInfo();
560
- let pageToSelect = Math.max(1, page);
561
- if (switchPageToSelectedRowPage && selectedRowIndex >= 0) {
562
- pageToSelect = getPageForRowIndex(selectedRowIndex, perPage);
563
- }
564
- const maxPageAmount = Math.ceil(source.count() / perPage);
565
- return maxPageAmount ? Math.min(pageToSelect, maxPageAmount) : pageToSelect;
566
- }
567
552
  }
568
553
 
569
554
  class EditCellDefault {
@@ -604,8 +589,9 @@ class CustomEditComponent extends EditCellDefault {
604
589
  this.resolver = resolver;
605
590
  }
606
591
  ngOnChanges(changes) {
607
- if (this.cell && !this.customComponent) {
608
- const componentFactory = this.resolver.resolveComponentFactory(this.cell.getColumn().editor.component);
592
+ const editor = this.cell.getColumn().editor;
593
+ if (this.cell && !this.customComponent && editor && editor.type == 'custom') {
594
+ const componentFactory = this.resolver.resolveComponentFactory(editor.component);
609
595
  this.customComponent = this.dynamicTarget.createComponent(componentFactory);
610
596
  // set @Inputs and @Outputs of custom component
611
597
  this.customComponent.instance.cell = this.cell;
@@ -640,6 +626,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
640
626
 
641
627
  class DefaultEditor {
642
628
  constructor() {
629
+ this.inputClass = '';
643
630
  this.onStopEditing = new EventEmitter();
644
631
  this.onEdited = new EventEmitter();
645
632
  this.onClick = new EventEmitter();
@@ -669,8 +656,9 @@ class CheckboxEditorComponent extends DefaultEditor {
669
656
  super();
670
657
  }
671
658
  onChange(event) {
672
- const trueVal = (this.cell.getColumn().getConfig() && this.cell.getColumn().getConfig().true) || true;
673
- const falseVal = (this.cell.getColumn().getConfig() && this.cell.getColumn().getConfig().false) || false;
659
+ const config = this.cell.getColumn().getConfig();
660
+ const trueVal = (config && config?.true) || true;
661
+ const falseVal = (config && config?.false) || false;
674
662
  this.cell.newValue = event.target.checked ? trueVal : falseVal;
675
663
  }
676
664
  }
@@ -681,7 +669,7 @@ CheckboxEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0"
681
669
  class="form-control"
682
670
  [name]="cell.getId()"
683
671
  [disabled]="!cell.isEditable()"
684
- [checked]="cell.getValue() == (cell.getColumn().getConfig()?.true || true)"
672
+ [checked]="cell.getValue() === (cell.getColumn().getConfig()?.true || true)"
685
673
  (click)="onClick.emit($event)"
686
674
  (change)="onChange($event)">
687
675
  `, isInline: true, styles: [":host input,:host textarea{width:100%;line-height:normal;padding:.375em .75em}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
@@ -693,55 +681,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
693
681
  class="form-control"
694
682
  [name]="cell.getId()"
695
683
  [disabled]="!cell.isEditable()"
696
- [checked]="cell.getValue() == (cell.getColumn().getConfig()?.true || true)"
684
+ [checked]="cell.getValue() === (cell.getColumn().getConfig()?.true || true)"
697
685
  (click)="onClick.emit($event)"
698
686
  (change)="onChange($event)">
699
687
  `, styles: [":host input,:host textarea{width:100%;line-height:normal;padding:.375em .75em}\n"] }]
700
688
  }], ctorParameters: function () { return []; } });
701
689
 
702
- class CompleterEditorComponent extends DefaultEditor {
703
- constructor() {
704
- super();
705
- this.completerStr = '';
706
- }
707
- ngOnInit() {
708
- // if (this.cell.getColumn().editor && this.cell.getColumn().editor.type === 'completer') {
709
- // const config = this.cell.getColumn().getConfig().completer;
710
- // config.dataService = this.completerService.local(config.data, config.searchFields, config.titleField);
711
- // config.dataService.descriptionField(config.descriptionField);
712
- // }
713
- }
714
- onEditedCompleter(event) {
715
- this.cell.newValue = event.title;
716
- return false;
717
- }
718
- }
719
- CompleterEditorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CompleterEditorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
720
- CompleterEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: CompleterEditorComponent, selector: "completer-editor", usesInheritance: true, ngImport: i0, template: `
721
- <!-- <ng2-completer [(ngModel)]="completerStr"
722
- [dataService]="cell.getColumn().getConfig().completer.dataService"
723
- [minSearchLength]="cell.getColumn().getConfig().completer.minSearchLength || 0"
724
- [pause]="cell.getColumn().getConfig().completer.pause || 0"
725
- [placeholder]="cell.getColumn().getConfig().completer.placeholder || 'Start typing...'"
726
- (selected)="onEditedCompleter($event)">
727
- </ng2-completer> -->
728
- `, isInline: true });
729
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CompleterEditorComponent, decorators: [{
730
- type: Component,
731
- args: [{
732
- selector: 'completer-editor',
733
- template: `
734
- <!-- <ng2-completer [(ngModel)]="completerStr"
735
- [dataService]="cell.getColumn().getConfig().completer.dataService"
736
- [minSearchLength]="cell.getColumn().getConfig().completer.minSearchLength || 0"
737
- [pause]="cell.getColumn().getConfig().completer.pause || 0"
738
- [placeholder]="cell.getColumn().getConfig().completer.placeholder || 'Start typing...'"
739
- (selected)="onEditedCompleter($event)">
740
- </ng2-completer> -->
741
- `,
742
- }]
743
- }], ctorParameters: function () { return []; } });
744
-
745
690
  class InputEditorComponent extends DefaultEditor {
746
691
  constructor() {
747
692
  super();
@@ -856,14 +801,18 @@ class DefaultEditComponent extends EditCellDefault {
856
801
  super();
857
802
  }
858
803
  getEditorType() {
859
- return this.cell.getColumn().editor && this.cell.getColumn().editor.type;
804
+ const editor = this.cell.getColumn().editor;
805
+ if (editor) {
806
+ return editor.type;
807
+ }
808
+ return 'text';
860
809
  }
861
810
  }
862
811
  DefaultEditComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultEditComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
863
- DefaultEditComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: DefaultEditComponent, selector: "table-cell-default-editor", usesInheritance: true, ngImport: i0, template: "<div [ngSwitch]=\"getEditorType()\">\n <select-editor *ngSwitchCase=\"'list'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </select-editor>\n\n <textarea-editor *ngSwitchCase=\"'textarea'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </textarea-editor>\n\n <checkbox-editor *ngSwitchCase=\"'checkbox'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\">\n </checkbox-editor>\n\n <completer-editor *ngSwitchCase=\"'completer'\"\n [cell]=\"cell\">\n </completer-editor>\n\n <input-editor *ngSwitchDefault\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </input-editor>\n</div>", dependencies: [{ kind: "directive", type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i1.NgSwitchDefault, selector: "[ngSwitchDefault]" }, { kind: "component", type: CheckboxEditorComponent, selector: "checkbox-editor" }, { kind: "component", type: CompleterEditorComponent, selector: "completer-editor" }, { kind: "component", type: InputEditorComponent, selector: "input-editor" }, { kind: "component", type: SelectEditorComponent, selector: "select-editor" }, { kind: "component", type: TextareaEditorComponent, selector: "textarea-editor" }] });
812
+ DefaultEditComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: DefaultEditComponent, selector: "table-cell-default-editor", usesInheritance: true, ngImport: i0, template: "<div [ngSwitch]=\"getEditorType()\">\n <select-editor *ngSwitchCase=\"'list'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </select-editor>\n\n <textarea-editor *ngSwitchCase=\"'textarea'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </textarea-editor>\n\n <checkbox-editor *ngSwitchCase=\"'checkbox'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\">\n </checkbox-editor>\n\n <input-editor *ngSwitchDefault\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </input-editor>\n</div>", dependencies: [{ kind: "directive", type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i1.NgSwitchDefault, selector: "[ngSwitchDefault]" }, { kind: "component", type: CheckboxEditorComponent, selector: "checkbox-editor" }, { kind: "component", type: InputEditorComponent, selector: "input-editor" }, { kind: "component", type: SelectEditorComponent, selector: "select-editor" }, { kind: "component", type: TextareaEditorComponent, selector: "textarea-editor" }] });
864
813
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultEditComponent, decorators: [{
865
814
  type: Component,
866
- args: [{ selector: 'table-cell-default-editor', template: "<div [ngSwitch]=\"getEditorType()\">\n <select-editor *ngSwitchCase=\"'list'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </select-editor>\n\n <textarea-editor *ngSwitchCase=\"'textarea'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </textarea-editor>\n\n <checkbox-editor *ngSwitchCase=\"'checkbox'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\">\n </checkbox-editor>\n\n <completer-editor *ngSwitchCase=\"'completer'\"\n [cell]=\"cell\">\n </completer-editor>\n\n <input-editor *ngSwitchDefault\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </input-editor>\n</div>" }]
815
+ args: [{ selector: 'table-cell-default-editor', template: "<div [ngSwitch]=\"getEditorType()\">\n <select-editor *ngSwitchCase=\"'list'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </select-editor>\n\n <textarea-editor *ngSwitchCase=\"'textarea'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </textarea-editor>\n\n <checkbox-editor *ngSwitchCase=\"'checkbox'\"\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\">\n </checkbox-editor>\n\n <input-editor *ngSwitchDefault\n [cell]=\"cell\"\n [inputClass]=\"inputClass\"\n (onClick)=\"onClick($event)\"\n (onEdited)=\"onEdited($event)\"\n (onStopEditing)=\"onStopEditing()\">\n </input-editor>\n</div>" }]
867
816
  }], ctorParameters: function () { return []; } });
868
817
 
869
818
  class EditCellComponent {
@@ -876,7 +825,11 @@ class EditCellComponent {
876
825
  return false;
877
826
  }
878
827
  getEditorType() {
879
- return this.cell.getColumn().editor && this.cell.getColumn().editor.type;
828
+ const editor = this.cell.getColumn().editor;
829
+ if (editor) {
830
+ return editor.type;
831
+ }
832
+ return 'text';
880
833
  }
881
834
  }
882
835
  EditCellComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EditCellComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
@@ -928,7 +881,6 @@ class CustomViewComponent {
928
881
  ngOnInit() {
929
882
  if (this.cell && !this.customComponent) {
930
883
  this.createCustomComponent();
931
- this.callOnComponentInit();
932
884
  this.patchInstance();
933
885
  }
934
886
  }
@@ -941,10 +893,6 @@ class CustomViewComponent {
941
893
  const componentFactory = this.resolver.resolveComponentFactory(this.cell.getColumn().renderComponent);
942
894
  this.customComponent = this.dynamicTarget.createComponent(componentFactory);
943
895
  }
944
- callOnComponentInit() {
945
- const onComponentInitFunction = this.cell.getColumn().getOnComponentInitFunction();
946
- onComponentInitFunction && onComponentInitFunction(this.customComponent.instance);
947
- }
948
896
  patchInstance() {
949
897
  Object.assign(this.customComponent.instance, this.getPatch());
950
898
  }
@@ -1067,7 +1015,6 @@ const CELL_COMPONENTS = [
1067
1015
  DefaultEditComponent,
1068
1016
  EditCellComponent,
1069
1017
  CheckboxEditorComponent,
1070
- CompleterEditorComponent,
1071
1018
  InputEditorComponent,
1072
1019
  SelectEditorComponent,
1073
1020
  TextareaEditorComponent,
@@ -1084,7 +1031,6 @@ CellModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15
1084
1031
  DefaultEditComponent,
1085
1032
  EditCellComponent,
1086
1033
  CheckboxEditorComponent,
1087
- CompleterEditorComponent,
1088
1034
  InputEditorComponent,
1089
1035
  SelectEditorComponent,
1090
1036
  TextareaEditorComponent,
@@ -1097,7 +1043,6 @@ CellModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15
1097
1043
  DefaultEditComponent,
1098
1044
  EditCellComponent,
1099
1045
  CheckboxEditorComponent,
1100
- CompleterEditorComponent,
1101
1046
  InputEditorComponent,
1102
1047
  SelectEditorComponent,
1103
1048
  TextareaEditorComponent,
@@ -1121,6 +1066,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1121
1066
  }]
1122
1067
  }] });
1123
1068
 
1069
+ function compareValues(direction, a, b) {
1070
+ if (a < b) {
1071
+ return -1 * direction;
1072
+ }
1073
+ if (a > b) {
1074
+ return direction;
1075
+ }
1076
+ return 0;
1077
+ }
1078
+ class LocalSorter {
1079
+ static sort(data, field, direction, customCompare) {
1080
+ const dir = (direction === 'asc') ? 1 : -1;
1081
+ const compare = customCompare ? customCompare : compareValues;
1082
+ return data.sort((a, b) => {
1083
+ return compare.call(null, dir, a[field], b[field]);
1084
+ });
1085
+ }
1086
+ }
1087
+
1088
+ function filterValues(value, search) {
1089
+ return value.toString().toLowerCase().includes(search.toString().toLowerCase());
1090
+ }
1091
+ class LocalFilter {
1092
+ static filter(data, field, search, customFilter) {
1093
+ const filter = customFilter ? customFilter : filterValues;
1094
+ return data.filter((el) => {
1095
+ const value = typeof el[field] === 'undefined' || el[field] === null ? '' : el[field];
1096
+ return filter.call(null, value, search);
1097
+ });
1098
+ }
1099
+ }
1100
+
1101
+ class LocalPager {
1102
+ static paginate(data, page, perPage) {
1103
+ return data.slice(perPage * (page - 1), perPage * page);
1104
+ }
1105
+ }
1106
+
1124
1107
  var SmartTableOnChangedEventName;
1125
1108
  (function (SmartTableOnChangedEventName) {
1126
1109
  SmartTableOnChangedEventName["load"] = "load";
@@ -1147,7 +1130,7 @@ class DataSource {
1147
1130
  refresh() {
1148
1131
  this.emitOnChanged(SmartTableOnChangedEventName.refresh);
1149
1132
  }
1150
- load(data) {
1133
+ loadEmit() {
1151
1134
  this.emitOnChanged(SmartTableOnChangedEventName.load);
1152
1135
  return Promise.resolve(true);
1153
1136
  }
@@ -1163,59 +1146,49 @@ class DataSource {
1163
1146
  onRemoved() {
1164
1147
  return this.onRemovedSource.asObservable();
1165
1148
  }
1166
- prepend(element) {
1149
+ prependEmit(element) {
1167
1150
  this.emitOnAdded(element);
1168
1151
  this.emitOnChanged(SmartTableOnChangedEventName.prepend);
1169
1152
  return Promise.resolve(true);
1170
1153
  }
1171
- append(element) {
1154
+ appendEmit(element) {
1172
1155
  this.emitOnAdded(element);
1173
1156
  this.emitOnChanged(SmartTableOnChangedEventName.append);
1174
1157
  return Promise.resolve(true);
1175
1158
  }
1176
- add(element) {
1159
+ addEmit(element) {
1177
1160
  this.emitOnAdded(element);
1178
1161
  this.emitOnChanged(SmartTableOnChangedEventName.add);
1179
1162
  return Promise.resolve(true);
1180
1163
  }
1181
- remove(element) {
1164
+ removeEmit(element) {
1182
1165
  this.emitOnRemoved(element);
1183
1166
  this.emitOnChanged(SmartTableOnChangedEventName.remove);
1184
1167
  return Promise.resolve(true);
1185
1168
  }
1186
- update(element, values) {
1169
+ updateEmit(element) {
1187
1170
  this.emitOnUpdated(element);
1188
1171
  this.emitOnChanged(SmartTableOnChangedEventName.update);
1189
1172
  return Promise.resolve(true);
1190
1173
  }
1191
- empty() {
1174
+ emptyEmit() {
1192
1175
  this.emitOnChanged(SmartTableOnChangedEventName.empty);
1193
1176
  return Promise.resolve(true);
1194
1177
  }
1195
- setSort(conf, doEmit) {
1196
- if (doEmit) {
1197
- this.emitOnChanged(SmartTableOnChangedEventName.sort);
1198
- }
1178
+ setSortEmit() {
1179
+ this.emitOnChanged(SmartTableOnChangedEventName.sort);
1199
1180
  }
1200
- setFilter(conf, andOperator, doEmit) {
1201
- if (doEmit) {
1202
- this.emitOnChanged(SmartTableOnChangedEventName.filter);
1203
- }
1181
+ setFilterEmit() {
1182
+ this.emitOnChanged(SmartTableOnChangedEventName.filter);
1204
1183
  }
1205
- addFilter(fieldConf, andOperator, doEmit) {
1206
- if (doEmit) {
1207
- this.emitOnChanged(SmartTableOnChangedEventName.filter);
1208
- }
1184
+ addFilterEmit() {
1185
+ this.emitOnChanged(SmartTableOnChangedEventName.filter);
1209
1186
  }
1210
- setPaging(page, perPage, doEmit) {
1211
- if (doEmit) {
1212
- this.emitOnChanged(SmartTableOnChangedEventName.paging);
1213
- }
1187
+ setPagingEmit() {
1188
+ this.emitOnChanged(SmartTableOnChangedEventName.paging);
1214
1189
  }
1215
- setPage(page, doEmit) {
1216
- if (doEmit) {
1217
- this.emitOnChanged(SmartTableOnChangedEventName.page);
1218
- }
1190
+ setPageEmit() {
1191
+ this.emitOnChanged(SmartTableOnChangedEventName.page);
1219
1192
  }
1220
1193
  emitOnRemoved(element) {
1221
1194
  this.onRemovedSource.next(element);
@@ -1237,1793 +1210,1747 @@ class DataSource {
1237
1210
  }
1238
1211
  }
1239
1212
 
1240
- class FilterDefault {
1241
- constructor() {
1242
- this.inputClass = '';
1243
- this.filter = new EventEmitter();
1244
- this.query = '';
1213
+ class LocalDataSource extends DataSource {
1214
+ constructor(data = []) {
1215
+ super();
1216
+ this.data = [];
1217
+ this.filteredAndSorted = [];
1218
+ this.sortConf = [];
1219
+ this.filterConf = {
1220
+ filters: [],
1221
+ andOperator: true,
1222
+ };
1223
+ this.pagingConf = false;
1224
+ this.data = data;
1245
1225
  }
1246
- onFilter(query) {
1247
- this.source.addFilter({
1248
- field: this.column.id,
1249
- search: query,
1250
- filter: this.column.getFilterFunction(),
1251
- });
1226
+ load(data) {
1227
+ this.data = data;
1228
+ return super.loadEmit();
1252
1229
  }
1253
- }
1254
- FilterDefault.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterDefault, deps: [], target: i0.ɵɵFactoryTarget.Component });
1255
- FilterDefault.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: FilterDefault, selector: "ng-component", inputs: { column: "column", source: "source", inputClass: "inputClass" }, outputs: { filter: "filter" }, ngImport: i0, template: '', isInline: true });
1256
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterDefault, decorators: [{
1257
- type: Component,
1258
- args: [{
1259
- template: '',
1260
- }]
1261
- }], propDecorators: { column: [{
1262
- type: Input
1263
- }], source: [{
1264
- type: Input
1265
- }], inputClass: [{
1266
- type: Input
1267
- }], filter: [{
1268
- type: Output
1269
- }] } });
1270
-
1271
- class DefaultFilter {
1272
- constructor() {
1273
- this.delay = 300;
1274
- this.filter = new EventEmitter();
1230
+ prepend(element) {
1231
+ this.reset(true);
1232
+ this.data.unshift(element);
1233
+ return super.prependEmit(element);
1275
1234
  }
1276
- ngOnDestroy() {
1277
- if (this.changesSubscription) {
1278
- this.changesSubscription.unsubscribe();
1279
- }
1235
+ append(element) {
1236
+ this.reset(true);
1237
+ this.data.push(element);
1238
+ return super.appendEmit(element);
1280
1239
  }
1281
- setFilter() {
1282
- this.filter.emit(this.query);
1240
+ add(element) {
1241
+ this.data.push(element);
1242
+ return super.addEmit(element);
1283
1243
  }
1284
- }
1285
- DefaultFilter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultFilter, deps: [], target: i0.ɵɵFactoryTarget.Component });
1286
- DefaultFilter.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: DefaultFilter, selector: "ng-component", inputs: { query: "query", inputClass: "inputClass", column: "column" }, outputs: { filter: "filter" }, ngImport: i0, template: '', isInline: true });
1287
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultFilter, decorators: [{
1288
- type: Component,
1289
- args: [{
1290
- template: '',
1291
- }]
1292
- }], propDecorators: { query: [{
1293
- type: Input
1294
- }], inputClass: [{
1295
- type: Input
1296
- }], column: [{
1297
- type: Input
1298
- }], filter: [{
1299
- type: Output
1300
- }] } });
1301
-
1302
- class CheckboxFilterComponent extends DefaultFilter {
1303
- constructor() {
1304
- super();
1305
- this.filterActive = false;
1306
- this.inputControl = new UntypedFormControl();
1244
+ remove(element) {
1245
+ this.data = this.data.filter(el => el !== element);
1246
+ return super.removeEmit(element);
1307
1247
  }
1308
- ngOnInit() {
1309
- this.changesSubscription = this.inputControl.valueChanges
1310
- .pipe(debounceTime(this.delay))
1311
- .subscribe((checked) => {
1312
- this.filterActive = true;
1313
- const trueVal = (this.column.getFilterConfig() && this.column.getFilterConfig().true) || true;
1314
- const falseVal = (this.column.getFilterConfig() && this.column.getFilterConfig().false) || false;
1315
- this.query = checked ? trueVal : falseVal;
1316
- this.setFilter();
1248
+ update(element, values) {
1249
+ return new Promise((resolve, reject) => {
1250
+ this.find(element).then((found) => {
1251
+ found = deepExtend(found, values);
1252
+ super.updateEmit(found).then(resolve).catch(reject);
1253
+ }).catch(reject);
1317
1254
  });
1318
1255
  }
1319
- resetFilter(event) {
1320
- event.preventDefault();
1321
- this.query = '';
1322
- this.inputControl.setValue(false, { emitEvent: false });
1323
- this.filterActive = false;
1324
- this.setFilter();
1325
- }
1326
- }
1327
- CheckboxFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CheckboxFilterComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1328
- CheckboxFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: CheckboxFilterComponent, selector: "checkbox-filter", usesInheritance: true, ngImport: i0, template: `
1329
- <input type="checkbox" [formControl]="inputControl" [ngClass]="inputClass" class="form-control">
1330
- <a href="#" *ngIf="filterActive"
1331
- (click)="resetFilter($event)">{{column.getFilterConfig()?.resetText || 'reset'}}</a>
1332
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] });
1333
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CheckboxFilterComponent, decorators: [{
1334
- type: Component,
1335
- args: [{
1336
- selector: 'checkbox-filter',
1337
- template: `
1338
- <input type="checkbox" [formControl]="inputControl" [ngClass]="inputClass" class="form-control">
1339
- <a href="#" *ngIf="filterActive"
1340
- (click)="resetFilter($event)">{{column.getFilterConfig()?.resetText || 'reset'}}</a>
1341
- `,
1342
- }]
1343
- }], ctorParameters: function () { return []; } });
1344
-
1345
- class CompleterFilterComponent extends DefaultFilter {
1346
- constructor() {
1347
- super();
1348
- this.completerContent = new Subject();
1349
- }
1350
- ngOnInit() {
1351
- // const config = this.column.getFilterConfig().completer;
1352
- // config.dataService = this.completerService.local(config.data, config.searchFields, config.titleField);
1353
- // config.dataService.descriptionField(config.descriptionField);
1354
- // this.changesSubscription = this.completerContent
1355
- // .pipe(
1356
- // map((ev: any) => (ev && ev.title) || ev || ''),
1357
- // distinctUntilChanged(),
1358
- // debounceTime(this.delay)
1359
- // )
1360
- // .subscribe((search: string) => {
1361
- // this.query = search;
1362
- // this.setFilter();
1363
- // });
1364
- }
1365
- inputTextChanged(event) {
1366
- // workaround to trigger the search event when the home/end buttons are clicked
1367
- // when this happens the [(ngModel)]="query" is set to "" but the (selected) method is not called
1368
- // so here it gets called manually
1369
- if (event === '') {
1370
- this.completerContent.next(event);
1256
+ find(element) {
1257
+ const found = this.data.find(el => el === element);
1258
+ if (found) {
1259
+ return Promise.resolve(found);
1371
1260
  }
1261
+ return Promise.reject(new Error('Element was not found in the dataset'));
1372
1262
  }
1373
- }
1374
- CompleterFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CompleterFilterComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1375
- CompleterFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: CompleterFilterComponent, selector: "completer-filter", usesInheritance: true, ngImport: i0, template: `
1376
- <!-- <ng2-completer [(ngModel)]="query"
1377
- (ngModelChange)="inputTextChanged($event)"
1378
- [dataService]="column.getFilterConfig().completer.dataService"
1379
- [minSearchLength]="column.getFilterConfig().completer.minSearchLength || 0"
1380
- [pause]="column.getFilterConfig().completer.pause || 0"
1381
- [placeholder]="column.getFilterConfig().completer.placeholder || 'Start typing...'"
1382
- (selected)="completerContent.next($event)">
1383
- </ng2-completer> -->
1384
- `, isInline: true });
1385
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CompleterFilterComponent, decorators: [{
1386
- type: Component,
1387
- args: [{
1388
- selector: 'completer-filter',
1389
- template: `
1390
- <!-- <ng2-completer [(ngModel)]="query"
1391
- (ngModelChange)="inputTextChanged($event)"
1392
- [dataService]="column.getFilterConfig().completer.dataService"
1393
- [minSearchLength]="column.getFilterConfig().completer.minSearchLength || 0"
1394
- [pause]="column.getFilterConfig().completer.pause || 0"
1395
- [placeholder]="column.getFilterConfig().completer.placeholder || 'Start typing...'"
1396
- (selected)="completerContent.next($event)">
1397
- </ng2-completer> -->
1398
- `,
1399
- }]
1400
- }], ctorParameters: function () { return []; } });
1401
-
1402
- class InputFilterComponent extends DefaultFilter {
1403
- constructor() {
1404
- super();
1405
- this.inputControl = new UntypedFormControl();
1263
+ getElements() {
1264
+ const data = this.data.slice(0);
1265
+ return Promise.resolve(this.prepareData(data));
1406
1266
  }
1407
- ngOnInit() {
1408
- if (this.query) {
1409
- this.inputControl.setValue(this.query);
1410
- }
1411
- this.inputControl.valueChanges
1412
- .pipe(distinctUntilChanged(), debounceTime(this.delay))
1413
- .subscribe((value) => {
1414
- this.query = this.inputControl.value;
1415
- this.setFilter();
1416
- });
1267
+ getFilteredAndSorted() {
1268
+ let data = this.data.slice(0);
1269
+ this.prepareData(data);
1270
+ return Promise.resolve(this.filteredAndSorted);
1417
1271
  }
1418
- ngOnChanges(changes) {
1419
- if (changes.query) {
1420
- this.inputControl.setValue(this.query);
1421
- }
1422
- }
1423
- }
1424
- InputFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: InputFilterComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1425
- InputFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: InputFilterComponent, selector: "input-filter", usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
1426
- <input
1427
- [ngClass]="inputClass"
1428
- [formControl]="inputControl"
1429
- class="form-control"
1430
- type="text"
1431
- placeholder="{{ column.title }}"/>
1432
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] });
1433
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: InputFilterComponent, decorators: [{
1434
- type: Component,
1435
- args: [{
1436
- selector: 'input-filter',
1437
- template: `
1438
- <input
1439
- [ngClass]="inputClass"
1440
- [formControl]="inputControl"
1441
- class="form-control"
1442
- type="text"
1443
- placeholder="{{ column.title }}"/>
1444
- `,
1445
- }]
1446
- }], ctorParameters: function () { return []; } });
1447
-
1448
- class SelectFilterComponent extends DefaultFilter {
1449
- constructor() {
1450
- super();
1451
- }
1452
- ngOnInit() {
1453
- this.inputControl.valueChanges
1454
- .pipe(skip(1), distinctUntilChanged(), debounceTime(this.delay))
1455
- .subscribe((value) => this.setFilter());
1456
- }
1457
- }
1458
- SelectFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SelectFilterComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1459
- SelectFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: SelectFilterComponent, selector: "select-filter", viewQueries: [{ propertyName: "inputControl", first: true, predicate: ["inputControl"], descendants: true, read: NgControl, static: true }], usesInheritance: true, ngImport: i0, template: `
1460
- <select [ngClass]="inputClass"
1461
- class="form-control"
1462
- #inputControl
1463
- [(ngModel)]="query">
1464
-
1465
- <option value="">{{ column.getFilterConfig().selectText }}</option>
1466
- <option *ngFor="let option of column.getFilterConfig().list" [value]="option.value">
1467
- {{ option.title }}
1468
- </option>
1469
- </select>
1470
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
1471
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SelectFilterComponent, decorators: [{
1472
- type: Component,
1473
- args: [{
1474
- selector: 'select-filter',
1475
- template: `
1476
- <select [ngClass]="inputClass"
1477
- class="form-control"
1478
- #inputControl
1479
- [(ngModel)]="query">
1480
-
1481
- <option value="">{{ column.getFilterConfig().selectText }}</option>
1482
- <option *ngFor="let option of column.getFilterConfig().list" [value]="option.value">
1483
- {{ option.title }}
1484
- </option>
1485
- </select>
1486
- `,
1487
- }]
1488
- }], ctorParameters: function () { return []; }, propDecorators: { inputControl: [{
1489
- type: ViewChild,
1490
- args: ['inputControl', { read: NgControl, static: true }]
1491
- }] } });
1492
-
1493
- class DefaultFilterComponent extends FilterDefault {
1494
- }
1495
- DefaultFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultFilterComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
1496
- DefaultFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: DefaultFilterComponent, selector: "default-table-filter", inputs: { query: "query" }, usesInheritance: true, ngImport: i0, template: `
1497
- <ng-container [ngSwitch]="column.getFilterType()">
1498
- <select-filter *ngSwitchCase="'list'"
1499
- [query]="query"
1500
- [ngClass]="inputClass"
1501
- [column]="column"
1502
- (filter)="onFilter($event)">
1503
- </select-filter>
1504
- <checkbox-filter *ngSwitchCase="'checkbox'"
1505
- [query]="query"
1506
- [ngClass]="inputClass"
1507
- [column]="column"
1508
- (filter)="onFilter($event)">
1509
- </checkbox-filter>
1510
- <completer-filter *ngSwitchCase="'completer'"
1511
- [query]="query"
1512
- [ngClass]="inputClass"
1513
- [column]="column"
1514
- (filter)="onFilter($event)">
1515
- </completer-filter>
1516
- <input-filter *ngSwitchDefault
1517
- [query]="query"
1518
- [ngClass]="inputClass"
1519
- [column]="column"
1520
- (filter)="onFilter($event)">
1521
- </input-filter>
1522
- </ng-container>
1523
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i1.NgSwitchDefault, selector: "[ngSwitchDefault]" }, { kind: "component", type: CheckboxFilterComponent, selector: "checkbox-filter" }, { kind: "component", type: CompleterFilterComponent, selector: "completer-filter" }, { kind: "component", type: InputFilterComponent, selector: "input-filter" }, { kind: "component", type: SelectFilterComponent, selector: "select-filter" }] });
1524
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultFilterComponent, decorators: [{
1525
- type: Component,
1526
- args: [{
1527
- selector: 'default-table-filter',
1528
- template: `
1529
- <ng-container [ngSwitch]="column.getFilterType()">
1530
- <select-filter *ngSwitchCase="'list'"
1531
- [query]="query"
1532
- [ngClass]="inputClass"
1533
- [column]="column"
1534
- (filter)="onFilter($event)">
1535
- </select-filter>
1536
- <checkbox-filter *ngSwitchCase="'checkbox'"
1537
- [query]="query"
1538
- [ngClass]="inputClass"
1539
- [column]="column"
1540
- (filter)="onFilter($event)">
1541
- </checkbox-filter>
1542
- <completer-filter *ngSwitchCase="'completer'"
1543
- [query]="query"
1544
- [ngClass]="inputClass"
1545
- [column]="column"
1546
- (filter)="onFilter($event)">
1547
- </completer-filter>
1548
- <input-filter *ngSwitchDefault
1549
- [query]="query"
1550
- [ngClass]="inputClass"
1551
- [column]="column"
1552
- (filter)="onFilter($event)">
1553
- </input-filter>
1554
- </ng-container>
1555
- `,
1556
- }]
1557
- }], propDecorators: { query: [{
1558
- type: Input
1559
- }] } });
1560
-
1561
- class CustomFilterComponent extends FilterDefault {
1562
- constructor(resolver) {
1563
- super();
1564
- this.resolver = resolver;
1272
+ getAll() {
1273
+ const data = this.data.slice(0);
1274
+ return Promise.resolve(data);
1565
1275
  }
1566
- ngOnChanges(changes) {
1567
- if (this.column && !this.customComponent) {
1568
- const componentFactory = this.resolver.resolveComponentFactory(this.column.filter.component);
1569
- this.customComponent = this.dynamicTarget.createComponent(componentFactory);
1570
- // set @Inputs and @Outputs of custom component
1571
- this.customComponent.instance.query = this.query;
1572
- this.customComponent.instance.column = this.column;
1573
- this.customComponent.instance.source = this.source;
1574
- this.customComponent.instance.inputClass = this.inputClass;
1575
- this.customComponent.instance.filter.subscribe((event) => this.onFilter(event));
1276
+ reset(silent = false) {
1277
+ if (silent) {
1278
+ this.filterConf = {
1279
+ filters: [],
1280
+ andOperator: true,
1281
+ };
1282
+ this.sortConf = [];
1283
+ if (this.pagingConf) {
1284
+ this.pagingConf.page = 1;
1285
+ }
1576
1286
  }
1577
- if (this.customComponent) {
1578
- this.customComponent.instance.ngOnChanges(changes);
1287
+ else {
1288
+ this.setFilter([], true, false);
1289
+ this.setSort([], false);
1290
+ if (this.pagingConf) {
1291
+ this.setPage(1);
1292
+ }
1579
1293
  }
1580
1294
  }
1581
- ngOnDestroy() {
1582
- if (this.customComponent) {
1583
- this.customComponent.destroy();
1584
- }
1295
+ empty() {
1296
+ this.data = [];
1297
+ return super.emptyEmit();
1585
1298
  }
1586
- }
1587
- CustomFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CustomFilterComponent, deps: [{ token: i0.ComponentFactoryResolver }], target: i0.ɵɵFactoryTarget.Component });
1588
- CustomFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: CustomFilterComponent, selector: "custom-table-filter", inputs: { query: "query" }, viewQueries: [{ propertyName: "dynamicTarget", first: true, predicate: ["dynamicTarget"], descendants: true, read: ViewContainerRef, static: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `<ng-template #dynamicTarget></ng-template>`, isInline: true });
1589
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CustomFilterComponent, decorators: [{
1590
- type: Component,
1591
- args: [{
1592
- selector: 'custom-table-filter',
1593
- template: `<ng-template #dynamicTarget></ng-template>`,
1594
- }]
1595
- }], ctorParameters: function () { return [{ type: i0.ComponentFactoryResolver }]; }, propDecorators: { query: [{
1596
- type: Input
1597
- }], dynamicTarget: [{
1598
- type: ViewChild,
1599
- args: ['dynamicTarget', { read: ViewContainerRef, static: true }]
1600
- }] } });
1601
-
1602
- class FilterComponent extends FilterDefault {
1603
- constructor() {
1604
- super(...arguments);
1605
- this.query = '';
1299
+ count() {
1300
+ return this.filteredAndSorted.length;
1606
1301
  }
1607
- ngOnChanges(changes) {
1608
- if (changes.source) {
1609
- if (!changes.source.firstChange) {
1610
- this.dataChangedSub.unsubscribe();
1611
- }
1612
- this.dataChangedSub = this.source.onChanged().subscribe((dataChanges) => {
1613
- const filterConf = this.source.getFilter();
1614
- if (filterConf && filterConf.filters && filterConf.filters.length === 0) {
1615
- this.query = '';
1616
- // add a check for existing filters an set the query if one exists for this column
1617
- // this covers instances where the filter is set by user code while maintaining existing functionality
1618
- }
1619
- else if (filterConf && filterConf.filters && filterConf.filters.length > 0) {
1620
- filterConf.filters.forEach((k, v) => {
1621
- if (k.field == this.column.id) {
1622
- this.query = k.search;
1623
- }
1624
- });
1302
+ /**
1303
+ *
1304
+ * Array of conf objects
1305
+ * [
1306
+ * {field: string, direction: asc|desc|null, compare: Function|null},
1307
+ * ]
1308
+ * @param conf
1309
+ * @param doEmit
1310
+ * @returns {LocalDataSource}
1311
+ */
1312
+ setSort(conf, doEmit = true) {
1313
+ if (conf !== null) {
1314
+ conf.forEach((fieldConf) => {
1315
+ if (!fieldConf.field || typeof fieldConf.direction === 'undefined') {
1316
+ throw new Error('Sort configuration object is not valid');
1625
1317
  }
1626
1318
  });
1319
+ this.sortConf = conf;
1627
1320
  }
1628
- }
1629
- }
1630
- FilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
1631
- FilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: FilterComponent, selector: "ng2-smart-table-filter", usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
1632
- <div class="ng2-smart-filter" *ngIf="column.isFilterable" [ngSwitch]="column.getFilterType()">
1633
- <custom-table-filter *ngSwitchCase="'custom'"
1634
- [query]="query"
1635
- [column]="column"
1636
- [source]="source"
1637
- [inputClass]="inputClass"
1638
- (filter)="onFilter($event)">
1639
- </custom-table-filter>
1640
- <default-table-filter *ngSwitchDefault
1641
- [query]="query"
1642
- [column]="column"
1643
- [source]="source"
1644
- [inputClass]="inputClass"
1645
- (filter)="onFilter($event)">
1646
- </default-table-filter>
1647
- </div>
1648
- `, isInline: true, styles: [":host .ng2-smart-filter ::ng-deep input,:host .ng2-smart-filter ::ng-deep select{width:100%;line-height:normal;padding:.375em .75em;font-weight:400}:host .ng2-smart-filter ::ng-deep input[type=search]{box-sizing:inherit}:host .ng2-smart-filter ::ng-deep .completer-dropdown-holder{font-weight:400}:host .ng2-smart-filter ::ng-deep a{font-weight:400}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i1.NgSwitchDefault, selector: "[ngSwitchDefault]" }, { kind: "component", type: DefaultFilterComponent, selector: "default-table-filter", inputs: ["query"] }, { kind: "component", type: CustomFilterComponent, selector: "custom-table-filter", inputs: ["query"] }] });
1649
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterComponent, decorators: [{
1650
- type: Component,
1651
- args: [{ selector: 'ng2-smart-table-filter', template: `
1652
- <div class="ng2-smart-filter" *ngIf="column.isFilterable" [ngSwitch]="column.getFilterType()">
1653
- <custom-table-filter *ngSwitchCase="'custom'"
1654
- [query]="query"
1655
- [column]="column"
1656
- [source]="source"
1657
- [inputClass]="inputClass"
1658
- (filter)="onFilter($event)">
1659
- </custom-table-filter>
1660
- <default-table-filter *ngSwitchDefault
1661
- [query]="query"
1662
- [column]="column"
1663
- [source]="source"
1664
- [inputClass]="inputClass"
1665
- (filter)="onFilter($event)">
1666
- </default-table-filter>
1667
- </div>
1668
- `, styles: [":host .ng2-smart-filter ::ng-deep input,:host .ng2-smart-filter ::ng-deep select{width:100%;line-height:normal;padding:.375em .75em;font-weight:400}:host .ng2-smart-filter ::ng-deep input[type=search]{box-sizing:inherit}:host .ng2-smart-filter ::ng-deep .completer-dropdown-holder{font-weight:400}:host .ng2-smart-filter ::ng-deep a{font-weight:400}\n"] }]
1669
- }] });
1670
-
1671
- const FILTER_COMPONENTS = [
1672
- FilterDefault,
1673
- DefaultFilter,
1674
- FilterComponent,
1675
- DefaultFilterComponent,
1676
- CustomFilterComponent,
1677
- CheckboxFilterComponent,
1678
- CompleterFilterComponent,
1679
- InputFilterComponent,
1680
- SelectFilterComponent,
1681
- ];
1682
- class FilterModule {
1683
- }
1684
- FilterModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1685
- FilterModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FilterModule, declarations: [FilterDefault,
1686
- DefaultFilter,
1687
- FilterComponent,
1688
- DefaultFilterComponent,
1689
- CustomFilterComponent,
1690
- CheckboxFilterComponent,
1691
- CompleterFilterComponent,
1692
- InputFilterComponent,
1693
- SelectFilterComponent], imports: [CommonModule,
1694
- FormsModule,
1695
- ReactiveFormsModule], exports: [FilterDefault,
1696
- DefaultFilter,
1697
- FilterComponent,
1698
- DefaultFilterComponent,
1699
- CustomFilterComponent,
1700
- CheckboxFilterComponent,
1701
- CompleterFilterComponent,
1702
- InputFilterComponent,
1703
- SelectFilterComponent] });
1704
- FilterModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterModule, imports: [CommonModule,
1705
- FormsModule,
1706
- ReactiveFormsModule] });
1707
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterModule, decorators: [{
1708
- type: NgModule,
1709
- args: [{
1710
- imports: [
1711
- CommonModule,
1712
- FormsModule,
1713
- ReactiveFormsModule,
1714
- ],
1715
- declarations: [
1716
- ...FILTER_COMPONENTS,
1717
- ],
1718
- exports: [
1719
- ...FILTER_COMPONENTS,
1720
- ],
1721
- }]
1722
- }] });
1723
-
1724
- class PagerComponent {
1725
- constructor() {
1726
- this.perPageSelect = [];
1727
- this.changePage = new EventEmitter();
1728
- this.count = 0;
1729
- }
1730
- ngOnChanges(changes) {
1731
- if (changes.source) {
1732
- if (!changes.source.firstChange) {
1733
- this.dataChangedSub.unsubscribe();
1734
- }
1735
- this.dataChangedSub = this.source.onChanged().subscribe((dataChanges) => {
1736
- this.page = this.source.getPaging().page;
1737
- this.perPage = this.source.getPaging().perPage;
1738
- this.currentPerPage = this.perPage;
1739
- this.count = this.source.count();
1740
- if (this.isPageOutOfBounce()) {
1741
- this.source.setPage(--this.page);
1742
- }
1743
- this.processPageChange(dataChanges);
1744
- this.initPages();
1745
- });
1321
+ if (doEmit) {
1322
+ super.setSortEmit();
1746
1323
  }
1324
+ return this;
1747
1325
  }
1748
1326
  /**
1749
- * We change the page here depending on the action performed against data source
1750
- * if a new element was added to the end of the table - then change the page to the last
1751
- * if a new element was added to the beginning of the table - then to the first page
1752
- * @param changes
1327
+ *
1328
+ * Array of conf objects
1329
+ * [
1330
+ * {field: string, search: string, filter: Function|null},
1331
+ * ]
1332
+ * @param conf
1333
+ * @param andOperator
1334
+ * @param doEmit
1335
+ * @returns {LocalDataSource}
1753
1336
  */
1754
- processPageChange(changes) {
1755
- if (changes['action'] === 'prepend') {
1756
- this.source.setPage(1);
1337
+ setFilter(conf, andOperator = true, doEmit = true) {
1338
+ if (conf && conf.length > 0) {
1339
+ conf.forEach((fieldConf) => {
1340
+ this.addFilter(fieldConf, andOperator, false);
1341
+ });
1342
+ }
1343
+ else {
1344
+ this.filterConf = {
1345
+ filters: [],
1346
+ andOperator: true,
1347
+ };
1348
+ }
1349
+ this.filterConf.andOperator = andOperator;
1350
+ if (this.pagingConf) {
1351
+ this.pagingConf.page = 1;
1757
1352
  }
1758
- if (changes['action'] === 'append') {
1759
- this.source.setPage(this.getLast());
1353
+ if (doEmit) {
1354
+ super.setFilterEmit();
1760
1355
  }
1356
+ return this;
1761
1357
  }
1762
- shouldShow() {
1763
- return this.source.count() > this.perPage;
1764
- }
1765
- paginate(page) {
1766
- this.source.setPage(page);
1767
- this.page = page;
1768
- this.changePage.emit({ page });
1769
- return false;
1358
+ addFilter(fieldConf, andOperator = true, doEmit = true) {
1359
+ if (!fieldConf.field || typeof fieldConf.search === 'undefined') {
1360
+ throw new Error('Filter configuration object is not valid');
1361
+ }
1362
+ let found = false;
1363
+ this.filterConf.filters.forEach((currentFieldConf, index) => {
1364
+ if (currentFieldConf.field === fieldConf.field) {
1365
+ this.filterConf.filters[index] = fieldConf;
1366
+ found = true;
1367
+ }
1368
+ });
1369
+ if (!found) {
1370
+ this.filterConf.filters.push(fieldConf);
1371
+ }
1372
+ this.filterConf.andOperator = andOperator;
1373
+ if (doEmit) {
1374
+ super.addFilterEmit();
1375
+ }
1376
+ return this;
1770
1377
  }
1771
- next() {
1772
- return this.paginate(this.getPage() + 1);
1378
+ setPaging(page = 1, perPage, doEmit = true) {
1379
+ if (this.pagingConf) {
1380
+ this.pagingConf.page = page;
1381
+ this.pagingConf.perPage = perPage;
1382
+ }
1383
+ else {
1384
+ this.pagingConf = {
1385
+ page, perPage
1386
+ };
1387
+ }
1388
+ if (doEmit) {
1389
+ super.setPagingEmit();
1390
+ }
1391
+ return;
1773
1392
  }
1774
- prev() {
1775
- return this.paginate(this.getPage() - 1);
1393
+ setPage(page, doEmit = true) {
1394
+ if (!this.pagingConf) {
1395
+ return;
1396
+ }
1397
+ this.pagingConf.page = page;
1398
+ if (doEmit) {
1399
+ super.setPageEmit();
1400
+ }
1401
+ return;
1776
1402
  }
1777
- getPage() {
1778
- return this.page;
1403
+ getSort() {
1404
+ return this.sortConf;
1779
1405
  }
1780
- getPages() {
1781
- return this.pages;
1406
+ getFilter() {
1407
+ return this.filterConf;
1782
1408
  }
1783
- getLast() {
1784
- return Math.ceil(this.count / this.perPage);
1409
+ getPaging() {
1410
+ return this.pagingConf;
1785
1411
  }
1786
- isPageOutOfBounce() {
1787
- return (this.page * this.perPage) >= (this.count + this.perPage) && this.page > 1;
1412
+ prepareData(data) {
1413
+ data = this.filter(data);
1414
+ data = this.sort(data);
1415
+ this.filteredAndSorted = data.slice(0);
1416
+ if (this.pagingConf) {
1417
+ return this.paginate(data);
1418
+ }
1419
+ else
1420
+ return data;
1788
1421
  }
1789
- initPages() {
1790
- const pagesCount = this.getLast();
1791
- let showPagesCount = 4;
1792
- showPagesCount = pagesCount < showPagesCount ? pagesCount : showPagesCount;
1793
- this.pages = [];
1794
- if (this.shouldShow()) {
1795
- let middleOne = Math.ceil(showPagesCount / 2);
1796
- middleOne = this.page >= middleOne ? this.page : middleOne;
1797
- let lastOne = middleOne + Math.floor(showPagesCount / 2);
1798
- lastOne = lastOne >= pagesCount ? pagesCount : lastOne;
1799
- const firstOne = lastOne - showPagesCount + 1;
1800
- for (let i = firstOne; i <= lastOne; i++) {
1801
- this.pages.push(i);
1802
- }
1422
+ sort(data) {
1423
+ if (this.sortConf) {
1424
+ this.sortConf.forEach((fieldConf) => {
1425
+ data = LocalSorter
1426
+ .sort(data, fieldConf.field, fieldConf.direction, fieldConf.compare);
1427
+ });
1803
1428
  }
1429
+ return data;
1804
1430
  }
1805
- onChangePerPage(event) {
1806
- if (this.currentPerPage) {
1807
- if (typeof this.currentPerPage === 'string' && this.currentPerPage.toLowerCase() === 'all') {
1808
- this.source.getPaging().perPage = null;
1431
+ // TODO: refactor?
1432
+ filter(data) {
1433
+ if (this.filterConf.filters) {
1434
+ if (this.filterConf.andOperator) {
1435
+ this.filterConf.filters.forEach((fieldConf) => {
1436
+ if (fieldConf.search?.length > 0) {
1437
+ data = LocalFilter
1438
+ .filter(data, fieldConf.field, fieldConf.search, fieldConf.filter);
1439
+ }
1440
+ });
1809
1441
  }
1810
1442
  else {
1811
- this.source.getPaging().perPage = this.currentPerPage * 1;
1812
- this.source.refresh();
1443
+ let mergedData = [];
1444
+ this.filterConf.filters.forEach((fieldConf) => {
1445
+ if (fieldConf.search?.length > 0) {
1446
+ mergedData = mergedData.concat(LocalFilter
1447
+ .filter(data, fieldConf.field, fieldConf.search, fieldConf.filter));
1448
+ }
1449
+ });
1450
+ // remove non unique items
1451
+ data = mergedData.filter((elem, pos, arr) => {
1452
+ return arr.indexOf(elem) === pos;
1453
+ });
1813
1454
  }
1814
- this.initPages();
1815
1455
  }
1456
+ return data;
1457
+ }
1458
+ paginate(data) {
1459
+ if (this.pagingConf && this.pagingConf.page && this.pagingConf.perPage) {
1460
+ data = LocalPager.paginate(data, this.pagingConf.page, this.pagingConf.perPage);
1461
+ }
1462
+ return data;
1816
1463
  }
1817
1464
  }
1818
- PagerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1819
- PagerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: PagerComponent, selector: "ng2-smart-table-pager", inputs: { source: "source", perPageSelect: "perPageSelect" }, outputs: { changePage: "changePage" }, usesOnChanges: true, ngImport: i0, template: `
1820
- <nav *ngIf="shouldShow()" class="ng2-smart-pagination-nav">
1821
- <ul class="ng2-smart-pagination pagination">
1822
- <li class="ng2-smart-page-item page-item" [ngClass]="{disabled: getPage() == 1}">
1823
- <a class="ng2-smart-page-link page-link" href="#"
1824
- (click)="getPage() == 1 ? false : paginate(1)" aria-label="First">
1825
- <span aria-hidden="true">&laquo;</span>
1826
- <span class="sr-only">First</span>
1827
- </a>
1828
- </li>
1829
- <li class="ng2-smart-page-item page-item" [ngClass]="{disabled: getPage() == 1}">
1830
- <a class="ng2-smart-page-link page-link page-link-prev" href="#"
1831
- (click)="getPage() == 1 ? false : prev()" aria-label="Prev">
1832
- <span aria-hidden="true">&lt;</span>
1833
- <span class="sr-only">Prev</span>
1834
- </a>
1835
- </li>
1836
- <li class="ng2-smart-page-item page-item"
1837
- [ngClass]="{active: getPage() == page}" *ngFor="let page of getPages()">
1838
- <span class="ng2-smart-page-link page-link"
1839
- *ngIf="getPage() == page">{{ page }} <span class="sr-only">(current)</span></span>
1840
- <a class="ng2-smart-page-link page-link" href="#"
1841
- (click)="paginate(page)" *ngIf="getPage() != page">{{ page }}</a>
1842
- </li>
1843
-
1844
- <li class="ng2-smart-page-item page-item"
1845
- [ngClass]="{disabled: getPage() == getLast()}">
1846
- <a class="ng2-smart-page-link page-link page-link-next" href="#"
1847
- (click)="getPage() == getLast() ? false : next()" aria-label="Next">
1848
- <span aria-hidden="true">&gt;</span>
1849
- <span class="sr-only">Next</span>
1850
- </a>
1851
- </li>
1852
-
1853
- <li class="ng2-smart-page-item page-item"
1854
- [ngClass]="{disabled: getPage() == getLast()}">
1855
- <a class="ng2-smart-page-link page-link" href="#"
1856
- (click)="getPage() == getLast() ? false : paginate(getLast())" aria-label="Last">
1857
- <span aria-hidden="true">&raquo;</span>
1858
- <span class="sr-only">Last</span>
1859
- </a>
1860
- </li>
1861
- </ul>
1862
- </nav>
1863
-
1864
- <nav *ngIf="perPageSelect && perPageSelect.length > 0" class="ng2-smart-pagination-per-page">
1865
- <label for="per-page">
1866
- Per Page:
1867
- </label>
1868
- <select (change)="onChangePerPage($event)" [(ngModel)]="currentPerPage" id="per-page">
1869
- <option *ngFor="let item of perPageSelect" [value]="item">{{ item }}</option>
1870
- </select>
1871
- </nav>
1872
- `, isInline: true, styles: [".ng2-smart-pagination{display:inline-flex;font-size:.875em;padding:0}.ng2-smart-pagination .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.ng2-smart-pagination .ng2-smart-page-item{display:inline}.ng2-smart-pagination .page-link-next,.ng2-smart-pagination .page-link-prev{font-size:10px}:host{display:flex;justify-content:space-between}:host select{margin:1rem 0 1rem 1rem}:host label{margin:1rem 0 1rem 1rem;line-height:2.5rem}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
1873
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerComponent, decorators: [{
1874
- type: Component,
1875
- args: [{ selector: 'ng2-smart-table-pager', template: `
1876
- <nav *ngIf="shouldShow()" class="ng2-smart-pagination-nav">
1877
- <ul class="ng2-smart-pagination pagination">
1878
- <li class="ng2-smart-page-item page-item" [ngClass]="{disabled: getPage() == 1}">
1879
- <a class="ng2-smart-page-link page-link" href="#"
1880
- (click)="getPage() == 1 ? false : paginate(1)" aria-label="First">
1881
- <span aria-hidden="true">&laquo;</span>
1882
- <span class="sr-only">First</span>
1883
- </a>
1884
- </li>
1885
- <li class="ng2-smart-page-item page-item" [ngClass]="{disabled: getPage() == 1}">
1886
- <a class="ng2-smart-page-link page-link page-link-prev" href="#"
1887
- (click)="getPage() == 1 ? false : prev()" aria-label="Prev">
1888
- <span aria-hidden="true">&lt;</span>
1889
- <span class="sr-only">Prev</span>
1890
- </a>
1891
- </li>
1892
- <li class="ng2-smart-page-item page-item"
1893
- [ngClass]="{active: getPage() == page}" *ngFor="let page of getPages()">
1894
- <span class="ng2-smart-page-link page-link"
1895
- *ngIf="getPage() == page">{{ page }} <span class="sr-only">(current)</span></span>
1896
- <a class="ng2-smart-page-link page-link" href="#"
1897
- (click)="paginate(page)" *ngIf="getPage() != page">{{ page }}</a>
1898
- </li>
1899
-
1900
- <li class="ng2-smart-page-item page-item"
1901
- [ngClass]="{disabled: getPage() == getLast()}">
1902
- <a class="ng2-smart-page-link page-link page-link-next" href="#"
1903
- (click)="getPage() == getLast() ? false : next()" aria-label="Next">
1904
- <span aria-hidden="true">&gt;</span>
1905
- <span class="sr-only">Next</span>
1906
- </a>
1907
- </li>
1908
-
1909
- <li class="ng2-smart-page-item page-item"
1910
- [ngClass]="{disabled: getPage() == getLast()}">
1911
- <a class="ng2-smart-page-link page-link" href="#"
1912
- (click)="getPage() == getLast() ? false : paginate(getLast())" aria-label="Last">
1913
- <span aria-hidden="true">&raquo;</span>
1914
- <span class="sr-only">Last</span>
1915
- </a>
1916
- </li>
1917
- </ul>
1918
- </nav>
1919
-
1920
- <nav *ngIf="perPageSelect && perPageSelect.length > 0" class="ng2-smart-pagination-per-page">
1921
- <label for="per-page">
1922
- Per Page:
1923
- </label>
1924
- <select (change)="onChangePerPage($event)" [(ngModel)]="currentPerPage" id="per-page">
1925
- <option *ngFor="let item of perPageSelect" [value]="item">{{ item }}</option>
1926
- </select>
1927
- </nav>
1928
- `, styles: [".ng2-smart-pagination{display:inline-flex;font-size:.875em;padding:0}.ng2-smart-pagination .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.ng2-smart-pagination .ng2-smart-page-item{display:inline}.ng2-smart-pagination .page-link-next,.ng2-smart-pagination .page-link-prev{font-size:10px}:host{display:flex;justify-content:space-between}:host select{margin:1rem 0 1rem 1rem}:host label{margin:1rem 0 1rem 1rem;line-height:2.5rem}\n"] }]
1929
- }], propDecorators: { source: [{
1930
- type: Input
1931
- }], perPageSelect: [{
1932
- type: Input
1933
- }], changePage: [{
1934
- type: Output
1935
- }] } });
1936
1465
 
1937
- class PagerModule {
1466
+ class FilterDefault {
1467
+ constructor() {
1468
+ this.inputClass = '';
1469
+ this.query = '';
1470
+ this.filter = new EventEmitter();
1471
+ }
1472
+ onFilter(query) {
1473
+ this.source.addFilter({
1474
+ field: this.column.id,
1475
+ search: query,
1476
+ filter: this.column.getFilterFunction(),
1477
+ });
1478
+ }
1938
1479
  }
1939
- PagerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1940
- PagerModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: PagerModule, declarations: [PagerComponent], imports: [CommonModule,
1941
- FormsModule], exports: [PagerComponent] });
1942
- PagerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerModule, imports: [CommonModule,
1943
- FormsModule] });
1944
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerModule, decorators: [{
1945
- type: NgModule,
1480
+ FilterDefault.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterDefault, deps: [], target: i0.ɵɵFactoryTarget.Component });
1481
+ FilterDefaultcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: FilterDefault, selector: "ng-component", inputs: { column: "column", source: "source", inputClass: "inputClass", query: "query" }, outputs: { filter: "filter" }, ngImport: i0, template: '', isInline: true });
1482
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterDefault, decorators: [{
1483
+ type: Component,
1946
1484
  args: [{
1947
- imports: [
1948
- CommonModule,
1949
- FormsModule,
1950
- ],
1951
- declarations: [
1952
- PagerComponent,
1953
- ],
1954
- exports: [
1955
- PagerComponent,
1956
- ],
1485
+ template: '',
1957
1486
  }]
1958
- }] });
1487
+ }], propDecorators: { column: [{
1488
+ type: Input
1489
+ }], source: [{
1490
+ type: Input
1491
+ }], inputClass: [{
1492
+ type: Input
1493
+ }], query: [{
1494
+ type: Input
1495
+ }], filter: [{
1496
+ type: Output
1497
+ }] } });
1959
1498
 
1960
- class TbodyCreateCancelComponent {
1961
- onSave(event) {
1962
- event.preventDefault();
1963
- event.stopPropagation();
1964
- this.grid.save(this.row, this.editConfirm);
1499
+ class DefaultFilter {
1500
+ constructor() {
1501
+ this.delay = 300;
1502
+ this.query = '';
1503
+ this.inputClass = '';
1504
+ this.filter = new EventEmitter();
1965
1505
  }
1966
- onCancelEdit(event) {
1967
- event.preventDefault();
1968
- event.stopPropagation();
1969
- this.editCancel.emit(true);
1970
- this.row.isInEditing = false;
1506
+ ngOnDestroy() {
1507
+ if (this.changesSubscription) {
1508
+ this.changesSubscription.unsubscribe();
1509
+ }
1971
1510
  }
1972
- ngOnChanges() {
1973
- this.saveButtonContent = this.grid.getSetting('edit.saveButtonContent');
1974
- this.cancelButtonContent = this.grid.getSetting('edit.cancelButtonContent');
1511
+ setFilter() {
1512
+ this.filter.emit(this.query);
1975
1513
  }
1976
1514
  }
1977
- TbodyCreateCancelComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyCreateCancelComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1978
- TbodyCreateCancelComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TbodyCreateCancelComponent, selector: "ng2-st-tbody-create-cancel", inputs: { grid: "grid", row: "row", editConfirm: "editConfirm", editCancel: "editCancel" }, usesOnChanges: true, ngImport: i0, template: `
1979
- <a href="#" class="ng2-smart-action ng2-smart-action-edit-save"
1980
- [innerHTML]="saveButtonContent" (click)="onSave($event)"></a>
1981
- <a href="#" class="ng2-smart-action ng2-smart-action-edit-cancel"
1982
- [innerHTML]="cancelButtonContent" (click)="onCancelEdit($event)"></a>
1983
- `, isInline: true });
1984
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyCreateCancelComponent, decorators: [{
1515
+ DefaultFilter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultFilter, deps: [], target: i0.ɵɵFactoryTarget.Component });
1516
+ DefaultFilter.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: DefaultFilter, selector: "ng-component", inputs: { query: "query", inputClass: "inputClass", column: "column" }, outputs: { filter: "filter" }, ngImport: i0, template: '', isInline: true });
1517
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultFilter, decorators: [{
1985
1518
  type: Component,
1986
1519
  args: [{
1987
- selector: 'ng2-st-tbody-create-cancel',
1988
- template: `
1989
- <a href="#" class="ng2-smart-action ng2-smart-action-edit-save"
1990
- [innerHTML]="saveButtonContent" (click)="onSave($event)"></a>
1991
- <a href="#" class="ng2-smart-action ng2-smart-action-edit-cancel"
1992
- [innerHTML]="cancelButtonContent" (click)="onCancelEdit($event)"></a>
1993
- `,
1520
+ template: '',
1994
1521
  }]
1995
- }], propDecorators: { grid: [{
1996
- type: Input
1997
- }], row: [{
1522
+ }], propDecorators: { query: [{
1998
1523
  type: Input
1999
- }], editConfirm: [{
1524
+ }], inputClass: [{
2000
1525
  type: Input
2001
- }], editCancel: [{
1526
+ }], column: [{
2002
1527
  type: Input
1528
+ }], filter: [{
1529
+ type: Output
2003
1530
  }] } });
2004
1531
 
2005
- class TbodyEditDeleteComponent {
1532
+ class CheckboxFilterComponent extends DefaultFilter {
2006
1533
  constructor() {
2007
- this.edit = new EventEmitter();
2008
- this.delete = new EventEmitter();
2009
- this.editRowSelect = new EventEmitter();
1534
+ super();
1535
+ this.filterActive = false;
1536
+ this.inputControl = new UntypedFormControl();
2010
1537
  }
2011
- onEdit(event) {
2012
- event.preventDefault();
2013
- event.stopPropagation();
2014
- this.editRowSelect.emit(this.row);
2015
- this.edit.emit({
2016
- data: this.row.getData(),
2017
- source: this.source,
1538
+ ngOnInit() {
1539
+ this.changesSubscription = this.inputControl.valueChanges
1540
+ .pipe(debounceTime(this.delay))
1541
+ .subscribe((checked) => {
1542
+ this.filterActive = true;
1543
+ const trueVal = (this.column.getFilterConfig() && this.column.getFilterConfig().true) || true;
1544
+ const falseVal = (this.column.getFilterConfig() && this.column.getFilterConfig().false) || false;
1545
+ this.query = checked ? trueVal : falseVal;
1546
+ this.setFilter();
2018
1547
  });
2019
- if (this.grid.getSetting('mode') !== 'external') {
2020
- this.grid.edit(this.row);
2021
- }
2022
1548
  }
2023
- onDelete(event) {
1549
+ resetFilter(event) {
2024
1550
  event.preventDefault();
2025
- event.stopPropagation();
2026
- if (this.grid.getSetting('mode') === 'external') {
2027
- this.delete.emit({
2028
- data: this.row.getData(),
2029
- source: this.source,
2030
- });
1551
+ this.query = '';
1552
+ this.inputControl.setValue(false, { emitEvent: false });
1553
+ this.filterActive = false;
1554
+ this.setFilter();
1555
+ }
1556
+ }
1557
+ CheckboxFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CheckboxFilterComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1558
+ CheckboxFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: CheckboxFilterComponent, selector: "checkbox-filter", usesInheritance: true, ngImport: i0, template: `
1559
+ <input type="checkbox" [formControl]="inputControl" [ngClass]="inputClass" class="form-control">
1560
+ <a href="#" *ngIf="filterActive"
1561
+ (click)="resetFilter($event)">{{column.getFilterConfig()?.resetText || 'reset'}}</a>
1562
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] });
1563
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CheckboxFilterComponent, decorators: [{
1564
+ type: Component,
1565
+ args: [{
1566
+ selector: 'checkbox-filter',
1567
+ template: `
1568
+ <input type="checkbox" [formControl]="inputControl" [ngClass]="inputClass" class="form-control">
1569
+ <a href="#" *ngIf="filterActive"
1570
+ (click)="resetFilter($event)">{{column.getFilterConfig()?.resetText || 'reset'}}</a>
1571
+ `,
1572
+ }]
1573
+ }], ctorParameters: function () { return []; } });
1574
+
1575
+ class InputFilterComponent extends DefaultFilter {
1576
+ constructor() {
1577
+ super();
1578
+ this.inputControl = new UntypedFormControl();
1579
+ }
1580
+ ngOnInit() {
1581
+ if (this.query) {
1582
+ this.inputControl.setValue(this.query);
2031
1583
  }
2032
- else {
2033
- this.grid.delete(this.row, this.deleteConfirm);
1584
+ this.inputControl.valueChanges
1585
+ .pipe(distinctUntilChanged(), debounceTime(this.delay))
1586
+ .subscribe((value) => {
1587
+ this.query = this.inputControl.value;
1588
+ this.setFilter();
1589
+ });
1590
+ }
1591
+ ngOnChanges(changes) {
1592
+ if (changes?.['query']) {
1593
+ this.inputControl.setValue(this.query);
2034
1594
  }
2035
1595
  }
2036
- ngOnChanges() {
2037
- this.isActionEdit = this.grid.getSetting('actions.edit');
2038
- this.isActionDelete = this.grid.getSetting('actions.delete');
2039
- this.editRowButtonContent = this.grid.getSetting('edit.editButtonContent');
2040
- this.deleteRowButtonContent = this.grid.getSetting('delete.deleteButtonContent');
1596
+ }
1597
+ InputFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: InputFilterComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1598
+ InputFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: InputFilterComponent, selector: "input-filter", usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
1599
+ <input
1600
+ [ngClass]="inputClass"
1601
+ [formControl]="inputControl"
1602
+ class="form-control"
1603
+ type="text"
1604
+ placeholder="{{ column.title }}"/>
1605
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] });
1606
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: InputFilterComponent, decorators: [{
1607
+ type: Component,
1608
+ args: [{
1609
+ selector: 'input-filter',
1610
+ template: `
1611
+ <input
1612
+ [ngClass]="inputClass"
1613
+ [formControl]="inputControl"
1614
+ class="form-control"
1615
+ type="text"
1616
+ placeholder="{{ column.title }}"/>
1617
+ `,
1618
+ }]
1619
+ }], ctorParameters: function () { return []; } });
1620
+
1621
+ class SelectFilterComponent extends DefaultFilter {
1622
+ constructor() {
1623
+ super();
1624
+ }
1625
+ ngOnInit() {
1626
+ if (this.inputControl.valueChanges) {
1627
+ this.inputControl.valueChanges
1628
+ .pipe(skip(1), distinctUntilChanged(), debounceTime(this.delay))
1629
+ .subscribe((value) => this.setFilter());
1630
+ }
2041
1631
  }
2042
1632
  }
2043
- TbodyEditDeleteComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyEditDeleteComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2044
- TbodyEditDeleteComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TbodyEditDeleteComponent, selector: "ng2-st-tbody-edit-delete", inputs: { grid: "grid", row: "row", source: "source", deleteConfirm: "deleteConfirm", editConfirm: "editConfirm" }, outputs: { edit: "edit", delete: "delete", editRowSelect: "editRowSelect" }, usesOnChanges: true, ngImport: i0, template: `
2045
- <a href="#" *ngIf="isActionEdit" class="ng2-smart-action ng2-smart-action-edit-edit"
2046
- [innerHTML]="editRowButtonContent" (click)="onEdit($event)"></a>
2047
- <a href="#" *ngIf="isActionDelete" class="ng2-smart-action ng2-smart-action-delete-delete"
2048
- [innerHTML]="deleteRowButtonContent" (click)="onDelete($event)"></a>
2049
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2050
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyEditDeleteComponent, decorators: [{
1633
+ SelectFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SelectFilterComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1634
+ SelectFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: SelectFilterComponent, selector: "select-filter", viewQueries: [{ propertyName: "inputControl", first: true, predicate: ["inputControl"], descendants: true, read: NgControl, static: true }], usesInheritance: true, ngImport: i0, template: `
1635
+ <select [ngClass]="inputClass"
1636
+ class="form-control"
1637
+ #inputControl
1638
+ [(ngModel)]="query">
1639
+
1640
+ <option value="">{{ column.getFilterConfig().selectText }}</option>
1641
+ <option *ngFor="let option of column.getFilterConfig().list" [value]="option.value">
1642
+ {{ option.title }}
1643
+ </option>
1644
+ </select>
1645
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
1646
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SelectFilterComponent, decorators: [{
1647
+ type: Component,
1648
+ args: [{
1649
+ selector: 'select-filter',
1650
+ template: `
1651
+ <select [ngClass]="inputClass"
1652
+ class="form-control"
1653
+ #inputControl
1654
+ [(ngModel)]="query">
1655
+
1656
+ <option value="">{{ column.getFilterConfig().selectText }}</option>
1657
+ <option *ngFor="let option of column.getFilterConfig().list" [value]="option.value">
1658
+ {{ option.title }}
1659
+ </option>
1660
+ </select>
1661
+ `,
1662
+ }]
1663
+ }], ctorParameters: function () { return []; }, propDecorators: { inputControl: [{
1664
+ type: ViewChild,
1665
+ args: ['inputControl', { read: NgControl, static: true }]
1666
+ }] } });
1667
+
1668
+ class DefaultFilterComponent extends FilterDefault {
1669
+ }
1670
+ DefaultFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultFilterComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
1671
+ DefaultFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: DefaultFilterComponent, selector: "default-table-filter", usesInheritance: true, ngImport: i0, template: `
1672
+ <ng-container [ngSwitch]="column.getFilterType()">
1673
+ <select-filter *ngSwitchCase="'list'"
1674
+ [query]="query"
1675
+ [ngClass]="inputClass"
1676
+ [column]="column"
1677
+ (filter)="onFilter($event)">
1678
+ </select-filter>
1679
+ <checkbox-filter *ngSwitchCase="'checkbox'"
1680
+ [query]="query"
1681
+ [ngClass]="inputClass"
1682
+ [column]="column"
1683
+ (filter)="onFilter($event)">
1684
+ </checkbox-filter>
1685
+ <input-filter *ngSwitchDefault
1686
+ [query]="query"
1687
+ [ngClass]="inputClass"
1688
+ [column]="column"
1689
+ (filter)="onFilter($event)">
1690
+ </input-filter>
1691
+ </ng-container>
1692
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i1.NgSwitchDefault, selector: "[ngSwitchDefault]" }, { kind: "component", type: CheckboxFilterComponent, selector: "checkbox-filter" }, { kind: "component", type: InputFilterComponent, selector: "input-filter" }, { kind: "component", type: SelectFilterComponent, selector: "select-filter" }] });
1693
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DefaultFilterComponent, decorators: [{
2051
1694
  type: Component,
2052
1695
  args: [{
2053
- selector: 'ng2-st-tbody-edit-delete',
2054
- changeDetection: ChangeDetectionStrategy.OnPush,
1696
+ selector: 'default-table-filter',
2055
1697
  template: `
2056
- <a href="#" *ngIf="isActionEdit" class="ng2-smart-action ng2-smart-action-edit-edit"
2057
- [innerHTML]="editRowButtonContent" (click)="onEdit($event)"></a>
2058
- <a href="#" *ngIf="isActionDelete" class="ng2-smart-action ng2-smart-action-delete-delete"
2059
- [innerHTML]="deleteRowButtonContent" (click)="onDelete($event)"></a>
1698
+ <ng-container [ngSwitch]="column.getFilterType()">
1699
+ <select-filter *ngSwitchCase="'list'"
1700
+ [query]="query"
1701
+ [ngClass]="inputClass"
1702
+ [column]="column"
1703
+ (filter)="onFilter($event)">
1704
+ </select-filter>
1705
+ <checkbox-filter *ngSwitchCase="'checkbox'"
1706
+ [query]="query"
1707
+ [ngClass]="inputClass"
1708
+ [column]="column"
1709
+ (filter)="onFilter($event)">
1710
+ </checkbox-filter>
1711
+ <input-filter *ngSwitchDefault
1712
+ [query]="query"
1713
+ [ngClass]="inputClass"
1714
+ [column]="column"
1715
+ (filter)="onFilter($event)">
1716
+ </input-filter>
1717
+ </ng-container>
2060
1718
  `,
2061
1719
  }]
2062
- }], propDecorators: { grid: [{
2063
- type: Input
2064
- }], row: [{
2065
- type: Input
2066
- }], source: [{
2067
- type: Input
2068
- }], deleteConfirm: [{
2069
- type: Input
2070
- }], editConfirm: [{
2071
- type: Input
2072
- }], edit: [{
2073
- type: Output
2074
- }], delete: [{
2075
- type: Output
2076
- }], editRowSelect: [{
2077
- type: Output
2078
- }] } });
1720
+ }] });
2079
1721
 
2080
- class TbodyCustomComponent {
2081
- constructor() {
2082
- this.custom = new EventEmitter();
1722
+ class CustomFilterComponent extends FilterDefault {
1723
+ constructor(resolver) {
1724
+ super();
1725
+ this.resolver = resolver;
2083
1726
  }
2084
- onCustom(action, event) {
2085
- event.preventDefault();
2086
- event.stopPropagation();
2087
- this.custom.emit({
2088
- action: action.name,
2089
- data: this.row.getData(),
2090
- source: this.source
2091
- });
1727
+ ngOnChanges(changes) {
1728
+ if (this.customComponent) {
1729
+ this.customComponent.instance.ngOnChanges(changes);
1730
+ return;
1731
+ }
1732
+ if (this.column.filter && this.column.filter.type === 'custom') {
1733
+ const componentFactory = this.resolver.resolveComponentFactory(this.column.filter?.component);
1734
+ this.customComponent = this.dynamicTarget.createComponent(componentFactory);
1735
+ }
1736
+ // set @Inputs and @Outputs of custom component
1737
+ this.customComponent.instance.query = this.query;
1738
+ this.customComponent.instance.column = this.column;
1739
+ this.customComponent.instance.source = this.source;
1740
+ this.customComponent.instance.inputClass = this.inputClass;
1741
+ this.customComponent.instance.filter.subscribe((event) => this.onFilter(event));
1742
+ }
1743
+ ngOnDestroy() {
1744
+ if (this.customComponent) {
1745
+ this.customComponent.destroy();
1746
+ }
2092
1747
  }
2093
1748
  }
2094
- TbodyCustomComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyCustomComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2095
- TbodyCustomComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TbodyCustomComponent, selector: "ng2-st-tbody-custom", inputs: { grid: "grid", row: "row", source: "source" }, outputs: { custom: "custom" }, ngImport: i0, template: `
2096
- <a *ngFor="let action of grid.getSetting('actions.custom')" href="#"
2097
- class="ng2-smart-action ng2-smart-action-custom-custom"
2098
- [innerHTML]="action.title"
2099
- (click)="onCustom(action, $event)"></a>
2100
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2101
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyCustomComponent, decorators: [{
1749
+ CustomFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CustomFilterComponent, deps: [{ token: i0.ComponentFactoryResolver }], target: i0.ɵɵFactoryTarget.Component });
1750
+ CustomFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: CustomFilterComponent, selector: "custom-table-filter", viewQueries: [{ propertyName: "dynamicTarget", first: true, predicate: ["dynamicTarget"], descendants: true, read: ViewContainerRef, static: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `<ng-template #dynamicTarget></ng-template>`, isInline: true });
1751
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CustomFilterComponent, decorators: [{
2102
1752
  type: Component,
2103
1753
  args: [{
2104
- selector: 'ng2-st-tbody-custom',
2105
- changeDetection: ChangeDetectionStrategy.OnPush,
2106
- template: `
2107
- <a *ngFor="let action of grid.getSetting('actions.custom')" href="#"
2108
- class="ng2-smart-action ng2-smart-action-custom-custom"
2109
- [innerHTML]="action.title"
2110
- (click)="onCustom(action, $event)"></a>
2111
- `
1754
+ selector: 'custom-table-filter',
1755
+ template: `<ng-template #dynamicTarget></ng-template>`,
2112
1756
  }]
2113
- }], propDecorators: { grid: [{
2114
- type: Input
2115
- }], row: [{
2116
- type: Input
2117
- }], source: [{
2118
- type: Input
2119
- }], custom: [{
2120
- type: Output
1757
+ }], ctorParameters: function () { return [{ type: i0.ComponentFactoryResolver }]; }, propDecorators: { dynamicTarget: [{
1758
+ type: ViewChild,
1759
+ args: ['dynamicTarget', { read: ViewContainerRef, static: true }]
2121
1760
  }] } });
2122
1761
 
2123
- class Ng2SmartTableTbodyComponent {
2124
- constructor() {
2125
- this.save = new EventEmitter();
2126
- this.cancel = new EventEmitter();
2127
- this.edit = new EventEmitter();
2128
- this.editCancel = new EventEmitter();
2129
- this.delete = new EventEmitter();
2130
- this.custom = new EventEmitter();
2131
- this.edited = new EventEmitter();
2132
- this.userSelectRow = new EventEmitter();
2133
- this.userClickedRow = new EventEmitter();
2134
- this.editRowSelect = new EventEmitter();
2135
- this.multipleSelectRow = new EventEmitter();
2136
- }
2137
- get tableColumnsCount() {
2138
- const actionColumns = this.isActionAdd || this.isActionEdit || this.isActionDelete ? 1 : 0;
2139
- return this.grid.getColumns().length + actionColumns;
2140
- }
2141
- ngOnChanges() {
2142
- this.isMultiSelectVisible = this.grid.isMultiSelectVisible();
2143
- this.showActionColumnLeft = this.grid.showActionColumn('left');
2144
- this.mode = this.grid.getSetting('mode');
2145
- this.editInputClass = this.grid.getSetting('edit.inputClass');
2146
- this.showActionColumnRight = this.grid.showActionColumn('right');
2147
- this.isActionAdd = this.grid.getSetting('actions.add');
2148
- this.isActionEdit = this.grid.getSetting('actions.edit');
2149
- this.isActionDelete = this.grid.getSetting('actions.delete');
2150
- this.noDataMessage = this.grid.getSetting('noDataMessage');
2151
- }
2152
- getVisibleCells(cells) {
2153
- return (cells || []).filter((cell) => !cell.getColumn().hide);
2154
- }
2155
- trackByIdOrIndex(index, item) {
2156
- return item?.id || index;
1762
+ class FilterComponent extends FilterDefault {
1763
+ ngOnChanges(changes) {
1764
+ if (changes['source']) {
1765
+ if (!changes['source'].firstChange && this.dataChangedSub) {
1766
+ this.dataChangedSub.unsubscribe();
1767
+ }
1768
+ this.dataChangedSub = this.source.onChanged().subscribe((dataChanges) => {
1769
+ const filterConf = this.source.getFilter();
1770
+ if (filterConf && filterConf.filters && filterConf.filters.length === 0) {
1771
+ this.query = '';
1772
+ // add a check for existing filters an set the query if one exists for this column
1773
+ // this covers instances where the filter is set by user code while maintaining existing functionality
1774
+ }
1775
+ else if (filterConf && filterConf.filters && filterConf.filters.length > 0) {
1776
+ filterConf.filters.forEach((k, v) => {
1777
+ if (k.field == this.column.id) {
1778
+ this.query = k.search;
1779
+ }
1780
+ });
1781
+ }
1782
+ });
1783
+ }
2157
1784
  }
2158
1785
  }
2159
- Ng2SmartTableTbodyComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: Ng2SmartTableTbodyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2160
- Ng2SmartTableTbodyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: Ng2SmartTableTbodyComponent, selector: "[ng2-st-tbody]", inputs: { grid: "grid", source: "source", deleteConfirm: "deleteConfirm", editConfirm: "editConfirm", rowClassFunction: "rowClassFunction" }, outputs: { save: "save", cancel: "cancel", edit: "edit", editCancel: "editCancel", delete: "delete", custom: "custom", edited: "edited", userSelectRow: "userSelectRow", userClickedRow: "userClickedRow", editRowSelect: "editRowSelect", multipleSelectRow: "multipleSelectRow" }, usesOnChanges: true, ngImport: i0, template: "<tr *ngFor=\"let row of grid.getRows(); trackBy: trackByIdOrIndex\" (click)=\"userClickedRow.emit(row)\" class=\"ng2-smart-row\" [className]=\"rowClassFunction(row)\" [ngClass]=\"{selected: row.isSelected}\">\n <td *ngIf=\"isMultiSelectVisible\" class=\"ng2-smart-actions ng2-smart-action-multiple-select\" (click)=\"multipleSelectRow.emit(row); $event.stopPropagation();\">\n <input type=\"checkbox\" class=\"form-control\" [ngModel]=\"row.isSelected\">\n </td>\n <td *ngIf=\"!row.isInEditing && showActionColumnLeft\" class=\"ng2-smart-actions\" (click)=\"$event.stopPropagation()\">\n <ng2-st-tbody-custom [grid]=\"grid\" (custom)=\"custom.emit($event)\" [row]=\"row\" [source]=\"source\"></ng2-st-tbody-custom>\n\n <ng2-st-tbody-edit-delete [grid]=\"grid\"\n [deleteConfirm]=\"deleteConfirm\"\n [editConfirm]=\"editConfirm\"\n (edit)=\"edit.emit(row)\"\n (delete)=\"delete.emit(row)\"\n (editRowSelect)=\"editRowSelect.emit($event)\"\n [row]=\"row\"\n [source]=\"source\">\n </ng2-st-tbody-edit-delete>\n </td>\n <td *ngIf=\"row.isInEditing && showActionColumnLeft\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-create-cancel [grid]=\"grid\" [row]=\"row\" [editConfirm]=\"editConfirm\" [editCancel]=\"editCancel\"></ng2-st-tbody-create-cancel>\n </td>\n <td *ngFor=\"let cell of getVisibleCells(row.cells)\">\n <ng2-smart-table-cell [cell]=\"cell\"\n [grid]=\"grid\"\n [row]=\"row\"\n [isNew]=\"false\"\n [mode]=\"mode\"\n [editConfirm]=\"editConfirm\"\n [inputClass]=\"editInputClass\"\n [isInEditing]=\"row.isInEditing\">\n </ng2-smart-table-cell>\n </td>\n\n <td *ngIf=\"row.isInEditing && showActionColumnRight\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-create-cancel [grid]=\"grid\" [row]=\"row\" [editConfirm]=\"editConfirm\"></ng2-st-tbody-create-cancel>\n </td>\n\n <td *ngIf=\"!row.isInEditing && showActionColumnRight\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-custom [grid]=\"grid\" (custom)=\"custom.emit($event)\" [row]=\"row\" [source]=\"source\"></ng2-st-tbody-custom>\n\n <ng2-st-tbody-edit-delete [grid]=\"grid\"\n [deleteConfirm]=\"deleteConfirm\"\n [editConfirm]=\"editConfirm\"\n [row]=\"row\"\n [source]=\"source\"\n (edit)=\"edit.emit(row)\"\n (delete)=\"delete.emit(row)\"\n (editRowSelect)=\"editRowSelect.emit($event)\">\n </ng2-st-tbody-edit-delete>\n </td>\n</tr>\n\n<tr *ngIf=\"grid.getRows().length == 0\">\n <td [attr.colspan]=\"tableColumnsCount\">\n {{ noDataMessage }}\n </td>\n</tr>\n", styles: [":host .ng2-smart-row.selected{background:rgba(0,0,0,.05)}:host .ng2-smart-row .ng2-smart-actions.ng2-smart-action-multiple-select{text-align:center}:host ::ng-deep ng2-st-tbody-edit-delete a:first-child,:host ::ng-deep ng2-st-tbody-create-cancel a:first-child{margin-right:.25rem}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: CellComponent, selector: "ng2-smart-table-cell", inputs: ["grid", "row", "editConfirm", "createConfirm", "isNew", "cell", "inputClass", "mode", "isInEditing"], outputs: ["edited"] }, { kind: "component", type: TbodyCreateCancelComponent, selector: "ng2-st-tbody-create-cancel", inputs: ["grid", "row", "editConfirm", "editCancel"] }, { kind: "component", type: TbodyEditDeleteComponent, selector: "ng2-st-tbody-edit-delete", inputs: ["grid", "row", "source", "deleteConfirm", "editConfirm"], outputs: ["edit", "delete", "editRowSelect"] }, { kind: "component", type: TbodyCustomComponent, selector: "ng2-st-tbody-custom", inputs: ["grid", "row", "source"], outputs: ["custom"] }] });
2161
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: Ng2SmartTableTbodyComponent, decorators: [{
1786
+ FilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
1787
+ FilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: FilterComponent, selector: "ng2-smart-table-filter", usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
1788
+ <div class="ng2-smart-filter" *ngIf="column.isFilterable" [ngSwitch]="column.getFilterType()">
1789
+ <custom-table-filter *ngSwitchCase="'custom'"
1790
+ [query]="query"
1791
+ [column]="column"
1792
+ [source]="source"
1793
+ [inputClass]="inputClass"
1794
+ (filter)="onFilter($event)">
1795
+ </custom-table-filter>
1796
+ <default-table-filter *ngSwitchDefault
1797
+ [query]="query"
1798
+ [column]="column"
1799
+ [source]="source"
1800
+ [inputClass]="inputClass"
1801
+ (filter)="onFilter($event)">
1802
+ </default-table-filter>
1803
+ </div>
1804
+ `, isInline: true, styles: [":host .ng2-smart-filter ::ng-deep input,:host .ng2-smart-filter ::ng-deep select{width:100%;line-height:normal;padding:.375em .75em;font-weight:400}:host .ng2-smart-filter ::ng-deep input[type=search]{box-sizing:inherit}:host .ng2-smart-filter ::ng-deep .completer-dropdown-holder{font-weight:400}:host .ng2-smart-filter ::ng-deep a{font-weight:400}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i1.NgSwitchDefault, selector: "[ngSwitchDefault]" }, { kind: "component", type: DefaultFilterComponent, selector: "default-table-filter" }, { kind: "component", type: CustomFilterComponent, selector: "custom-table-filter" }] });
1805
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterComponent, decorators: [{
2162
1806
  type: Component,
2163
- args: [{ selector: '[ng2-st-tbody]', template: "<tr *ngFor=\"let row of grid.getRows(); trackBy: trackByIdOrIndex\" (click)=\"userClickedRow.emit(row)\" class=\"ng2-smart-row\" [className]=\"rowClassFunction(row)\" [ngClass]=\"{selected: row.isSelected}\">\n <td *ngIf=\"isMultiSelectVisible\" class=\"ng2-smart-actions ng2-smart-action-multiple-select\" (click)=\"multipleSelectRow.emit(row); $event.stopPropagation();\">\n <input type=\"checkbox\" class=\"form-control\" [ngModel]=\"row.isSelected\">\n </td>\n <td *ngIf=\"!row.isInEditing && showActionColumnLeft\" class=\"ng2-smart-actions\" (click)=\"$event.stopPropagation()\">\n <ng2-st-tbody-custom [grid]=\"grid\" (custom)=\"custom.emit($event)\" [row]=\"row\" [source]=\"source\"></ng2-st-tbody-custom>\n\n <ng2-st-tbody-edit-delete [grid]=\"grid\"\n [deleteConfirm]=\"deleteConfirm\"\n [editConfirm]=\"editConfirm\"\n (edit)=\"edit.emit(row)\"\n (delete)=\"delete.emit(row)\"\n (editRowSelect)=\"editRowSelect.emit($event)\"\n [row]=\"row\"\n [source]=\"source\">\n </ng2-st-tbody-edit-delete>\n </td>\n <td *ngIf=\"row.isInEditing && showActionColumnLeft\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-create-cancel [grid]=\"grid\" [row]=\"row\" [editConfirm]=\"editConfirm\" [editCancel]=\"editCancel\"></ng2-st-tbody-create-cancel>\n </td>\n <td *ngFor=\"let cell of getVisibleCells(row.cells)\">\n <ng2-smart-table-cell [cell]=\"cell\"\n [grid]=\"grid\"\n [row]=\"row\"\n [isNew]=\"false\"\n [mode]=\"mode\"\n [editConfirm]=\"editConfirm\"\n [inputClass]=\"editInputClass\"\n [isInEditing]=\"row.isInEditing\">\n </ng2-smart-table-cell>\n </td>\n\n <td *ngIf=\"row.isInEditing && showActionColumnRight\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-create-cancel [grid]=\"grid\" [row]=\"row\" [editConfirm]=\"editConfirm\"></ng2-st-tbody-create-cancel>\n </td>\n\n <td *ngIf=\"!row.isInEditing && showActionColumnRight\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-custom [grid]=\"grid\" (custom)=\"custom.emit($event)\" [row]=\"row\" [source]=\"source\"></ng2-st-tbody-custom>\n\n <ng2-st-tbody-edit-delete [grid]=\"grid\"\n [deleteConfirm]=\"deleteConfirm\"\n [editConfirm]=\"editConfirm\"\n [row]=\"row\"\n [source]=\"source\"\n (edit)=\"edit.emit(row)\"\n (delete)=\"delete.emit(row)\"\n (editRowSelect)=\"editRowSelect.emit($event)\">\n </ng2-st-tbody-edit-delete>\n </td>\n</tr>\n\n<tr *ngIf=\"grid.getRows().length == 0\">\n <td [attr.colspan]=\"tableColumnsCount\">\n {{ noDataMessage }}\n </td>\n</tr>\n", styles: [":host .ng2-smart-row.selected{background:rgba(0,0,0,.05)}:host .ng2-smart-row .ng2-smart-actions.ng2-smart-action-multiple-select{text-align:center}:host ::ng-deep ng2-st-tbody-edit-delete a:first-child,:host ::ng-deep ng2-st-tbody-create-cancel a:first-child{margin-right:.25rem}\n"] }]
2164
- }], propDecorators: { grid: [{
2165
- type: Input
2166
- }], source: [{
2167
- type: Input
2168
- }], deleteConfirm: [{
2169
- type: Input
2170
- }], editConfirm: [{
2171
- type: Input
2172
- }], rowClassFunction: [{
2173
- type: Input
2174
- }], save: [{
2175
- type: Output
2176
- }], cancel: [{
2177
- type: Output
2178
- }], edit: [{
2179
- type: Output
2180
- }], editCancel: [{
2181
- type: Output
2182
- }], delete: [{
2183
- type: Output
2184
- }], custom: [{
2185
- type: Output
2186
- }], edited: [{
2187
- type: Output
2188
- }], userSelectRow: [{
2189
- type: Output
2190
- }], userClickedRow: [{
2191
- type: Output
2192
- }], editRowSelect: [{
2193
- type: Output
2194
- }], multipleSelectRow: [{
2195
- type: Output
2196
- }] } });
1807
+ args: [{ selector: 'ng2-smart-table-filter', template: `
1808
+ <div class="ng2-smart-filter" *ngIf="column.isFilterable" [ngSwitch]="column.getFilterType()">
1809
+ <custom-table-filter *ngSwitchCase="'custom'"
1810
+ [query]="query"
1811
+ [column]="column"
1812
+ [source]="source"
1813
+ [inputClass]="inputClass"
1814
+ (filter)="onFilter($event)">
1815
+ </custom-table-filter>
1816
+ <default-table-filter *ngSwitchDefault
1817
+ [query]="query"
1818
+ [column]="column"
1819
+ [source]="source"
1820
+ [inputClass]="inputClass"
1821
+ (filter)="onFilter($event)">
1822
+ </default-table-filter>
1823
+ </div>
1824
+ `, styles: [":host .ng2-smart-filter ::ng-deep input,:host .ng2-smart-filter ::ng-deep select{width:100%;line-height:normal;padding:.375em .75em;font-weight:400}:host .ng2-smart-filter ::ng-deep input[type=search]{box-sizing:inherit}:host .ng2-smart-filter ::ng-deep .completer-dropdown-holder{font-weight:400}:host .ng2-smart-filter ::ng-deep a{font-weight:400}\n"] }]
1825
+ }] });
2197
1826
 
2198
- const TBODY_COMPONENTS = [
2199
- TbodyCreateCancelComponent,
2200
- TbodyEditDeleteComponent,
2201
- TbodyCustomComponent,
2202
- Ng2SmartTableTbodyComponent
1827
+ const FILTER_COMPONENTS = [
1828
+ FilterDefault,
1829
+ DefaultFilter,
1830
+ FilterComponent,
1831
+ DefaultFilterComponent,
1832
+ CustomFilterComponent,
1833
+ CheckboxFilterComponent,
1834
+ InputFilterComponent,
1835
+ SelectFilterComponent,
2203
1836
  ];
2204
- class TBodyModule {
1837
+ class FilterModule {
2205
1838
  }
2206
- TBodyModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TBodyModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2207
- TBodyModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: TBodyModule, declarations: [TbodyCreateCancelComponent,
2208
- TbodyEditDeleteComponent,
2209
- TbodyCustomComponent,
2210
- Ng2SmartTableTbodyComponent], imports: [CommonModule,
1839
+ FilterModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1840
+ FilterModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FilterModule, declarations: [FilterDefault,
1841
+ DefaultFilter,
1842
+ FilterComponent,
1843
+ DefaultFilterComponent,
1844
+ CustomFilterComponent,
1845
+ CheckboxFilterComponent,
1846
+ InputFilterComponent,
1847
+ SelectFilterComponent], imports: [CommonModule,
2211
1848
  FormsModule,
2212
- CellModule], exports: [TbodyCreateCancelComponent,
2213
- TbodyEditDeleteComponent,
2214
- TbodyCustomComponent,
2215
- Ng2SmartTableTbodyComponent] });
2216
- TBodyModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TBodyModule, imports: [CommonModule,
1849
+ ReactiveFormsModule], exports: [FilterDefault,
1850
+ DefaultFilter,
1851
+ FilterComponent,
1852
+ DefaultFilterComponent,
1853
+ CustomFilterComponent,
1854
+ CheckboxFilterComponent,
1855
+ InputFilterComponent,
1856
+ SelectFilterComponent] });
1857
+ FilterModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterModule, imports: [CommonModule,
2217
1858
  FormsModule,
2218
- CellModule] });
2219
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TBodyModule, decorators: [{
1859
+ ReactiveFormsModule] });
1860
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FilterModule, decorators: [{
2220
1861
  type: NgModule,
2221
1862
  args: [{
2222
1863
  imports: [
2223
1864
  CommonModule,
2224
1865
  FormsModule,
2225
- CellModule,
1866
+ ReactiveFormsModule,
2226
1867
  ],
2227
1868
  declarations: [
2228
- ...TBODY_COMPONENTS,
1869
+ ...FILTER_COMPONENTS,
2229
1870
  ],
2230
1871
  exports: [
2231
- ...TBODY_COMPONENTS,
1872
+ ...FILTER_COMPONENTS,
2232
1873
  ],
2233
1874
  }]
2234
1875
  }] });
2235
1876
 
2236
- class AddButtonComponent {
2237
- constructor(ref) {
2238
- this.ref = ref;
2239
- this.create = new EventEmitter();
1877
+ class PagerComponent {
1878
+ constructor() {
1879
+ this.perPageSelect = [];
1880
+ this.changePage = new EventEmitter();
1881
+ this.currentPerPage = 0;
1882
+ this.pages = [];
1883
+ this.page = 1;
1884
+ this.count = 0;
1885
+ this.perPage = 0;
2240
1886
  }
2241
- ngAfterViewInit() {
2242
- this.ref.nativeElement.classList.add('ng2-smart-actions-title', 'ng2-smart-actions-title-add');
1887
+ ngOnChanges(changes) {
1888
+ if (changes['source']) {
1889
+ if (!changes['source'].firstChange && this.dataChangedSub) {
1890
+ this.dataChangedSub.unsubscribe();
1891
+ }
1892
+ this.dataChangedSub = this.source.onChanged().subscribe((dataChanges) => {
1893
+ const paging = this.source.getPaging();
1894
+ if (paging) {
1895
+ this.page = paging.page;
1896
+ this.perPage = paging.perPage;
1897
+ }
1898
+ this.currentPerPage = this.perPage;
1899
+ this.count = this.source.count();
1900
+ if (this.isPageOutOfBounce()) {
1901
+ this.source.setPage(--this.page);
1902
+ }
1903
+ this.processPageChange(dataChanges);
1904
+ this.initPages();
1905
+ });
1906
+ }
2243
1907
  }
2244
- ngOnChanges() {
2245
- this.isActionAdd = this.grid.getSetting('actions.add');
2246
- this.addNewButtonContent = this.grid.getSetting('add.addButtonContent');
1908
+ /**
1909
+ * We change the page here depending on the action performed against data source
1910
+ * if a new element was added to the end of the table - then change the page to the last
1911
+ * if a new element was added to the beginning of the table - then to the first page
1912
+ * @param changes
1913
+ */
1914
+ processPageChange(changes) {
1915
+ if (changes['action'] === 'prepend') {
1916
+ this.source.setPage(1);
1917
+ }
1918
+ if (changes['action'] === 'append') {
1919
+ this.source.setPage(this.getLast());
1920
+ }
2247
1921
  }
2248
- onAdd(event) {
2249
- event.preventDefault();
2250
- event.stopPropagation();
2251
- if (this.grid.getSetting('mode') === 'external') {
2252
- this.create.emit({
2253
- source: this.source,
2254
- });
1922
+ shouldShow() {
1923
+ return this.source.count() > this.perPage;
1924
+ }
1925
+ paginate(page) {
1926
+ this.source.setPage(page);
1927
+ this.page = page;
1928
+ this.changePage.emit({ page });
1929
+ return false;
1930
+ }
1931
+ next() {
1932
+ return this.paginate(this.getPage() + 1);
1933
+ }
1934
+ prev() {
1935
+ return this.paginate(this.getPage() - 1);
1936
+ }
1937
+ getPage() {
1938
+ return this.page;
1939
+ }
1940
+ getPages() {
1941
+ return this.pages;
1942
+ }
1943
+ getLast() {
1944
+ return Math.ceil(this.count / this.perPage);
1945
+ }
1946
+ isPageOutOfBounce() {
1947
+ return (this.page * this.perPage) >= (this.count + this.perPage) && this.page > 1;
1948
+ }
1949
+ initPages() {
1950
+ const pagesCount = this.getLast();
1951
+ let showPagesCount = 4;
1952
+ showPagesCount = pagesCount < showPagesCount ? pagesCount : showPagesCount;
1953
+ this.pages = [];
1954
+ if (this.shouldShow()) {
1955
+ let middleOne = Math.ceil(showPagesCount / 2);
1956
+ middleOne = this.page >= middleOne ? this.page : middleOne;
1957
+ let lastOne = middleOne + Math.floor(showPagesCount / 2);
1958
+ lastOne = lastOne >= pagesCount ? pagesCount : lastOne;
1959
+ const firstOne = lastOne - showPagesCount + 1;
1960
+ for (let i = firstOne; i <= lastOne; i++) {
1961
+ this.pages.push(i);
1962
+ }
2255
1963
  }
2256
- else {
2257
- this.grid.createFormShown = true;
1964
+ }
1965
+ onChangePerPage() {
1966
+ const paging = this.source.getPaging();
1967
+ if (paging) {
1968
+ paging.perPage = this.currentPerPage * 1;
2258
1969
  }
1970
+ this.source.refresh();
1971
+ this.initPages();
2259
1972
  }
2260
1973
  }
2261
- AddButtonComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AddButtonComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
2262
- AddButtonComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: AddButtonComponent, selector: "[ng2-st-add-button]", inputs: { grid: "grid", source: "source" }, outputs: { create: "create" }, usesOnChanges: true, ngImport: i0, template: `
2263
- <a *ngIf="isActionAdd" href="#" class="ng2-smart-action ng2-smart-action-add-add"
2264
- [innerHTML]="addNewButtonContent" (click)="onAdd($event)"></a>
2265
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
2266
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AddButtonComponent, decorators: [{
1974
+ PagerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1975
+ PagerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: PagerComponent, selector: "ng2-smart-table-pager", inputs: { source: "source", perPageSelect: "perPageSelect" }, outputs: { changePage: "changePage" }, usesOnChanges: true, ngImport: i0, template: `
1976
+ <nav *ngIf="shouldShow()" class="ng2-smart-pagination-nav">
1977
+ <ul class="ng2-smart-pagination pagination">
1978
+ <li class="ng2-smart-page-item page-item" [ngClass]="{disabled: getPage() == 1}">
1979
+ <a class="ng2-smart-page-link page-link" href="#"
1980
+ (click)="getPage() == 1 ? false : paginate(1)" aria-label="First">
1981
+ <span aria-hidden="true">&laquo;</span>
1982
+ <span class="sr-only">First</span>
1983
+ </a>
1984
+ </li>
1985
+ <li class="ng2-smart-page-item page-item" [ngClass]="{disabled: getPage() == 1}">
1986
+ <a class="ng2-smart-page-link page-link page-link-prev" href="#"
1987
+ (click)="getPage() == 1 ? false : prev()" aria-label="Prev">
1988
+ <span aria-hidden="true">&lt;</span>
1989
+ <span class="sr-only">Prev</span>
1990
+ </a>
1991
+ </li>
1992
+ <li class="ng2-smart-page-item page-item"
1993
+ [ngClass]="{active: getPage() == page}" *ngFor="let page of getPages()">
1994
+ <span class="ng2-smart-page-link page-link"
1995
+ *ngIf="getPage() == page">{{ page }} <span class="sr-only">(current)</span></span>
1996
+ <a class="ng2-smart-page-link page-link" href="#"
1997
+ (click)="paginate(page)" *ngIf="getPage() != page">{{ page }}</a>
1998
+ </li>
1999
+
2000
+ <li class="ng2-smart-page-item page-item"
2001
+ [ngClass]="{disabled: getPage() == getLast()}">
2002
+ <a class="ng2-smart-page-link page-link page-link-next" href="#"
2003
+ (click)="getPage() == getLast() ? false : next()" aria-label="Next">
2004
+ <span aria-hidden="true">&gt;</span>
2005
+ <span class="sr-only">Next</span>
2006
+ </a>
2007
+ </li>
2008
+
2009
+ <li class="ng2-smart-page-item page-item"
2010
+ [ngClass]="{disabled: getPage() == getLast()}">
2011
+ <a class="ng2-smart-page-link page-link" href="#"
2012
+ (click)="getPage() == getLast() ? false : paginate(getLast())" aria-label="Last">
2013
+ <span aria-hidden="true">&raquo;</span>
2014
+ <span class="sr-only">Last</span>
2015
+ </a>
2016
+ </li>
2017
+ </ul>
2018
+ </nav>
2019
+
2020
+ <nav *ngIf="perPageSelect && perPageSelect.length > 0" class="ng2-smart-pagination-per-page">
2021
+ <label for="per-page">
2022
+ Per Page:
2023
+ </label>
2024
+ <select (change)="onChangePerPage()" [(ngModel)]="currentPerPage" id="per-page">
2025
+ <option *ngFor="let item of perPageSelect" [value]="item">{{ item }}</option>
2026
+ </select>
2027
+ </nav>
2028
+ `, isInline: true, styles: [".ng2-smart-pagination{display:inline-flex;font-size:.875em;padding:0}.ng2-smart-pagination .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.ng2-smart-pagination .ng2-smart-page-item{display:inline}.ng2-smart-pagination .page-link-next,.ng2-smart-pagination .page-link-prev{font-size:10px}:host{display:flex;justify-content:space-between}:host select{margin:1rem 0 1rem 1rem}:host label{margin:1rem 0 1rem 1rem;line-height:2.5rem}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
2029
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerComponent, decorators: [{
2267
2030
  type: Component,
2268
- args: [{
2269
- selector: '[ng2-st-add-button]',
2270
- template: `
2271
- <a *ngIf="isActionAdd" href="#" class="ng2-smart-action ng2-smart-action-add-add"
2272
- [innerHTML]="addNewButtonContent" (click)="onAdd($event)"></a>
2273
- `,
2031
+ args: [{ selector: 'ng2-smart-table-pager', template: `
2032
+ <nav *ngIf="shouldShow()" class="ng2-smart-pagination-nav">
2033
+ <ul class="ng2-smart-pagination pagination">
2034
+ <li class="ng2-smart-page-item page-item" [ngClass]="{disabled: getPage() == 1}">
2035
+ <a class="ng2-smart-page-link page-link" href="#"
2036
+ (click)="getPage() == 1 ? false : paginate(1)" aria-label="First">
2037
+ <span aria-hidden="true">&laquo;</span>
2038
+ <span class="sr-only">First</span>
2039
+ </a>
2040
+ </li>
2041
+ <li class="ng2-smart-page-item page-item" [ngClass]="{disabled: getPage() == 1}">
2042
+ <a class="ng2-smart-page-link page-link page-link-prev" href="#"
2043
+ (click)="getPage() == 1 ? false : prev()" aria-label="Prev">
2044
+ <span aria-hidden="true">&lt;</span>
2045
+ <span class="sr-only">Prev</span>
2046
+ </a>
2047
+ </li>
2048
+ <li class="ng2-smart-page-item page-item"
2049
+ [ngClass]="{active: getPage() == page}" *ngFor="let page of getPages()">
2050
+ <span class="ng2-smart-page-link page-link"
2051
+ *ngIf="getPage() == page">{{ page }} <span class="sr-only">(current)</span></span>
2052
+ <a class="ng2-smart-page-link page-link" href="#"
2053
+ (click)="paginate(page)" *ngIf="getPage() != page">{{ page }}</a>
2054
+ </li>
2055
+
2056
+ <li class="ng2-smart-page-item page-item"
2057
+ [ngClass]="{disabled: getPage() == getLast()}">
2058
+ <a class="ng2-smart-page-link page-link page-link-next" href="#"
2059
+ (click)="getPage() == getLast() ? false : next()" aria-label="Next">
2060
+ <span aria-hidden="true">&gt;</span>
2061
+ <span class="sr-only">Next</span>
2062
+ </a>
2063
+ </li>
2064
+
2065
+ <li class="ng2-smart-page-item page-item"
2066
+ [ngClass]="{disabled: getPage() == getLast()}">
2067
+ <a class="ng2-smart-page-link page-link" href="#"
2068
+ (click)="getPage() == getLast() ? false : paginate(getLast())" aria-label="Last">
2069
+ <span aria-hidden="true">&raquo;</span>
2070
+ <span class="sr-only">Last</span>
2071
+ </a>
2072
+ </li>
2073
+ </ul>
2074
+ </nav>
2075
+
2076
+ <nav *ngIf="perPageSelect && perPageSelect.length > 0" class="ng2-smart-pagination-per-page">
2077
+ <label for="per-page">
2078
+ Per Page:
2079
+ </label>
2080
+ <select (change)="onChangePerPage()" [(ngModel)]="currentPerPage" id="per-page">
2081
+ <option *ngFor="let item of perPageSelect" [value]="item">{{ item }}</option>
2082
+ </select>
2083
+ </nav>
2084
+ `, styles: [".ng2-smart-pagination{display:inline-flex;font-size:.875em;padding:0}.ng2-smart-pagination .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.ng2-smart-pagination .ng2-smart-page-item{display:inline}.ng2-smart-pagination .page-link-next,.ng2-smart-pagination .page-link-prev{font-size:10px}:host{display:flex;justify-content:space-between}:host select{margin:1rem 0 1rem 1rem}:host label{margin:1rem 0 1rem 1rem;line-height:2.5rem}\n"] }]
2085
+ }], propDecorators: { source: [{
2086
+ type: Input
2087
+ }], perPageSelect: [{
2088
+ type: Input
2089
+ }], changePage: [{
2090
+ type: Output
2091
+ }] } });
2092
+
2093
+ class PagerModule {
2094
+ }
2095
+ PagerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2096
+ PagerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: PagerModule, declarations: [PagerComponent], imports: [CommonModule,
2097
+ FormsModule], exports: [PagerComponent] });
2098
+ PagerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerModule, imports: [CommonModule,
2099
+ FormsModule] });
2100
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PagerModule, decorators: [{
2101
+ type: NgModule,
2102
+ args: [{
2103
+ imports: [
2104
+ CommonModule,
2105
+ FormsModule,
2106
+ ],
2107
+ declarations: [
2108
+ PagerComponent,
2109
+ ],
2110
+ exports: [
2111
+ PagerComponent,
2112
+ ],
2274
2113
  }]
2275
- }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { grid: [{
2276
- type: Input
2277
- }], source: [{
2278
- type: Input
2279
- }], create: [{
2280
- type: Output
2281
- }] } });
2114
+ }] });
2282
2115
 
2283
- class TheadFitlersRowComponent {
2116
+ class TbodyCreateCancelComponent {
2284
2117
  constructor() {
2285
- this.create = new EventEmitter();
2286
- this.filter = new EventEmitter();
2118
+ this.cancelButtonContent = '';
2119
+ this.saveButtonContent = '';
2287
2120
  }
2288
- ngOnChanges() {
2289
- this.isMultiSelectVisible = this.grid.isMultiSelectVisible();
2290
- this.showActionColumnLeft = this.grid.showActionColumn('left');
2291
- this.showActionColumnRight = this.grid.showActionColumn('right');
2292
- this.filterInputClass = this.grid.getSetting('filter.inputClass');
2121
+ onSave(event) {
2122
+ event.preventDefault();
2123
+ event.stopPropagation();
2124
+ this.grid.save(this.row, this.editConfirm);
2293
2125
  }
2294
- getVisibleColumns(columns) {
2295
- return (columns || []).filter((column) => !column.hide);
2126
+ onCancelEdit(event) {
2127
+ event.preventDefault();
2128
+ event.stopPropagation();
2129
+ this.editCancel.emit(true);
2130
+ this.row.isInEditing = false;
2131
+ }
2132
+ ngOnChanges() {
2133
+ this.saveButtonContent = this.grid.getSetting('edit.saveButtonContent', 'save');
2134
+ this.cancelButtonContent = this.grid.getSetting('edit.cancelButtonContent', 'cancel');
2296
2135
  }
2297
2136
  }
2298
- TheadFitlersRowComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadFitlersRowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2299
- TheadFitlersRowComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TheadFitlersRowComponent, selector: "[ng2-st-thead-filters-row]", inputs: { grid: "grid", source: "source" }, outputs: { create: "create", filter: "filter" }, usesOnChanges: true, ngImport: i0, template: `
2300
- <th *ngIf="isMultiSelectVisible"></th>
2301
- <th ng2-st-add-button *ngIf="showActionColumnLeft"
2302
- [grid]="grid"
2303
- (create)="create.emit($event)">
2304
- </th>
2305
- <th *ngFor="let column of getVisibleColumns(grid.getColumns())" class="ng2-smart-th {{ column.id }}">
2306
- <ng2-smart-table-filter [source]="source"
2307
- [column]="column"
2308
- [inputClass]="filterInputClass"
2309
- (filter)="filter.emit($event)">
2310
- </ng2-smart-table-filter>
2311
- </th>
2312
- <th ng2-st-add-button *ngIf="showActionColumnRight"
2313
- [grid]="grid"
2314
- [source]="source"
2315
- (create)="create.emit($event)">
2316
- </th>
2317
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: FilterComponent, selector: "ng2-smart-table-filter" }, { kind: "component", type: AddButtonComponent, selector: "[ng2-st-add-button]", inputs: ["grid", "source"], outputs: ["create"] }] });
2318
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadFitlersRowComponent, decorators: [{
2137
+ TbodyCreateCancelComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyCreateCancelComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2138
+ TbodyCreateCancelComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TbodyCreateCancelComponent, selector: "ng2-st-tbody-create-cancel", inputs: { grid: "grid", row: "row", editConfirm: "editConfirm", editCancel: "editCancel" }, usesOnChanges: true, ngImport: i0, template: `
2139
+ <a href="#" class="ng2-smart-action ng2-smart-action-edit-save"
2140
+ [innerHTML]="saveButtonContent" (click)="onSave($event)"></a>
2141
+ <a href="#" class="ng2-smart-action ng2-smart-action-edit-cancel"
2142
+ [innerHTML]="cancelButtonContent" (click)="onCancelEdit($event)"></a>
2143
+ `, isInline: true });
2144
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyCreateCancelComponent, decorators: [{
2319
2145
  type: Component,
2320
2146
  args: [{
2321
- selector: '[ng2-st-thead-filters-row]',
2147
+ selector: 'ng2-st-tbody-create-cancel',
2322
2148
  template: `
2323
- <th *ngIf="isMultiSelectVisible"></th>
2324
- <th ng2-st-add-button *ngIf="showActionColumnLeft"
2325
- [grid]="grid"
2326
- (create)="create.emit($event)">
2327
- </th>
2328
- <th *ngFor="let column of getVisibleColumns(grid.getColumns())" class="ng2-smart-th {{ column.id }}">
2329
- <ng2-smart-table-filter [source]="source"
2330
- [column]="column"
2331
- [inputClass]="filterInputClass"
2332
- (filter)="filter.emit($event)">
2333
- </ng2-smart-table-filter>
2334
- </th>
2335
- <th ng2-st-add-button *ngIf="showActionColumnRight"
2336
- [grid]="grid"
2337
- [source]="source"
2338
- (create)="create.emit($event)">
2339
- </th>
2149
+ <a href="#" class="ng2-smart-action ng2-smart-action-edit-save"
2150
+ [innerHTML]="saveButtonContent" (click)="onSave($event)"></a>
2151
+ <a href="#" class="ng2-smart-action ng2-smart-action-edit-cancel"
2152
+ [innerHTML]="cancelButtonContent" (click)="onCancelEdit($event)"></a>
2340
2153
  `,
2341
2154
  }]
2342
2155
  }], propDecorators: { grid: [{
2343
2156
  type: Input
2344
- }], source: [{
2157
+ }], row: [{
2158
+ type: Input
2159
+ }], editConfirm: [{
2160
+ type: Input
2161
+ }], editCancel: [{
2345
2162
  type: Input
2346
- }], create: [{
2347
- type: Output
2348
- }], filter: [{
2349
- type: Output
2350
2163
  }] } });
2351
2164
 
2352
- class ActionsComponent {
2165
+ class TbodyEditDeleteComponent {
2353
2166
  constructor() {
2354
- this.create = new EventEmitter();
2167
+ this.edit = new EventEmitter();
2168
+ this.delete = new EventEmitter();
2169
+ this.editRowSelect = new EventEmitter();
2170
+ this.isActionEdit = false;
2171
+ this.isActionDelete = false;
2172
+ this.editRowButtonContent = '';
2173
+ this.deleteRowButtonContent = '';
2174
+ }
2175
+ onEdit(event) {
2176
+ event.preventDefault();
2177
+ event.stopPropagation();
2178
+ this.editRowSelect.emit(this.row);
2179
+ this.edit.emit({
2180
+ data: this.row.getData(),
2181
+ source: this.source,
2182
+ });
2183
+ if (this.grid.getSetting('mode') !== 'external') {
2184
+ this.grid.edit(this.row);
2185
+ }
2186
+ }
2187
+ onDelete(event) {
2188
+ event.preventDefault();
2189
+ event.stopPropagation();
2190
+ if (this.grid.getSetting('mode') === 'external') {
2191
+ this.delete.emit({
2192
+ data: this.row.getData(),
2193
+ source: this.source,
2194
+ });
2195
+ }
2196
+ else {
2197
+ this.grid.delete(this.row, this.deleteConfirm);
2198
+ }
2355
2199
  }
2356
2200
  ngOnChanges() {
2357
- this.createButtonContent = this.grid.getSetting('add.createButtonContent');
2358
- this.cancelButtonContent = this.grid.getSetting('add.cancelButtonContent');
2201
+ this.isActionEdit = this.grid.getSetting('actions.edit');
2202
+ this.isActionDelete = this.grid.getSetting('actions.delete');
2203
+ this.editRowButtonContent = this.grid.getSetting('edit.editButtonContent');
2204
+ this.deleteRowButtonContent = this.grid.getSetting('delete.deleteButtonContent');
2359
2205
  }
2360
2206
  }
2361
- ActionsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2362
- ActionsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: ActionsComponent, selector: "ng2-st-actions", inputs: { grid: "grid" }, outputs: { create: "create" }, usesOnChanges: true, ngImport: i0, template: `
2363
- <a href="#" class="ng2-smart-action ng2-smart-action-add-create"
2364
- [innerHTML]="createButtonContent"
2365
- (click)="$event.preventDefault();create.emit($event)"></a>
2366
- <a href="#" class="ng2-smart-action ng2-smart-action-add-cancel"
2367
- [innerHTML]="cancelButtonContent"
2368
- (click)="$event.preventDefault();grid.createFormShown = false;"></a>
2369
- `, isInline: true });
2370
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionsComponent, decorators: [{
2207
+ TbodyEditDeleteComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyEditDeleteComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2208
+ TbodyEditDeleteComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TbodyEditDeleteComponent, selector: "ng2-st-tbody-edit-delete", inputs: { grid: "grid", row: "row", source: "source", deleteConfirm: "deleteConfirm", editConfirm: "editConfirm" }, outputs: { edit: "edit", delete: "delete", editRowSelect: "editRowSelect" }, usesOnChanges: true, ngImport: i0, template: `
2209
+ <a href="#" *ngIf="isActionEdit" class="ng2-smart-action ng2-smart-action-edit-edit"
2210
+ [innerHTML]="editRowButtonContent" (click)="onEdit($event)"></a>
2211
+ <a href="#" *ngIf="isActionDelete" class="ng2-smart-action ng2-smart-action-delete-delete"
2212
+ [innerHTML]="deleteRowButtonContent" (click)="onDelete($event)"></a>
2213
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2214
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyEditDeleteComponent, decorators: [{
2371
2215
  type: Component,
2372
2216
  args: [{
2373
- selector: 'ng2-st-actions',
2217
+ selector: 'ng2-st-tbody-edit-delete',
2218
+ changeDetection: ChangeDetectionStrategy.OnPush,
2374
2219
  template: `
2375
- <a href="#" class="ng2-smart-action ng2-smart-action-add-create"
2376
- [innerHTML]="createButtonContent"
2377
- (click)="$event.preventDefault();create.emit($event)"></a>
2378
- <a href="#" class="ng2-smart-action ng2-smart-action-add-cancel"
2379
- [innerHTML]="cancelButtonContent"
2380
- (click)="$event.preventDefault();grid.createFormShown = false;"></a>
2220
+ <a href="#" *ngIf="isActionEdit" class="ng2-smart-action ng2-smart-action-edit-edit"
2221
+ [innerHTML]="editRowButtonContent" (click)="onEdit($event)"></a>
2222
+ <a href="#" *ngIf="isActionDelete" class="ng2-smart-action ng2-smart-action-delete-delete"
2223
+ [innerHTML]="deleteRowButtonContent" (click)="onDelete($event)"></a>
2381
2224
  `,
2382
2225
  }]
2383
2226
  }], propDecorators: { grid: [{
2384
2227
  type: Input
2385
- }], create: [{
2228
+ }], row: [{
2229
+ type: Input
2230
+ }], source: [{
2231
+ type: Input
2232
+ }], deleteConfirm: [{
2233
+ type: Input
2234
+ }], editConfirm: [{
2235
+ type: Input
2236
+ }], edit: [{
2237
+ type: Output
2238
+ }], delete: [{
2239
+ type: Output
2240
+ }], editRowSelect: [{
2386
2241
  type: Output
2387
2242
  }] } });
2388
2243
 
2389
- class TheadFormRowComponent {
2244
+ class TbodyCustomComponent {
2390
2245
  constructor() {
2391
- this.create = new EventEmitter();
2246
+ this.custom = new EventEmitter();
2392
2247
  }
2393
- onCreate(event) {
2248
+ onCustom(action, event) {
2249
+ event.preventDefault();
2394
2250
  event.stopPropagation();
2395
- this.grid.create(this.grid.getNewRow(), this.createConfirm);
2396
- }
2397
- ngOnChanges() {
2398
- this.isMultiSelectVisible = this.grid.isMultiSelectVisible();
2399
- this.showActionColumnLeft = this.grid.showActionColumn('left');
2400
- this.showActionColumnRight = this.grid.showActionColumn('right');
2401
- this.addInputClass = this.grid.getSetting('add.inputClass');
2402
- }
2403
- getVisibleCells(cells) {
2404
- return (cells || []).filter((cell) => !cell.getColumn().hide);
2251
+ this.custom.emit({
2252
+ action: action.name,
2253
+ data: this.row.getData(),
2254
+ source: this.source
2255
+ });
2405
2256
  }
2406
2257
  }
2407
- TheadFormRowComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadFormRowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2408
- TheadFormRowComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TheadFormRowComponent, selector: "[ng2-st-thead-form-row]", inputs: { grid: "grid", row: "row", createConfirm: "createConfirm" }, outputs: { create: "create" }, usesOnChanges: true, ngImport: i0, template: `
2409
- <td *ngIf="grid.isMultiSelectVisible"></td>
2410
- <td *ngIf="showActionColumnLeft" class="ng2-smart-actions">
2411
- <ng2-st-actions [grid]="grid" (create)="onCreate($event)"></ng2-st-actions>
2412
- </td>
2413
- <td *ngFor="let cell of getVisibleCells(grid.getNewRow().getCells())">
2414
- <ng2-smart-table-cell [cell]="cell"
2415
- [grid]="grid"
2416
- [isNew]="true"
2417
- [createConfirm]="createConfirm"
2418
- [inputClass]="addInputClass"
2419
- [isInEditing]="grid.getNewRow().isInEditing"
2420
- (edited)="onCreate($event)">
2421
- </ng2-smart-table-cell>
2422
- </td>
2423
- <td *ngIf="showActionColumnRight" class="ng2-smart-actions">
2424
- <ng2-st-actions [grid]="grid" (create)="onCreate($event)"></ng2-st-actions>
2425
- </td>
2426
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: CellComponent, selector: "ng2-smart-table-cell", inputs: ["grid", "row", "editConfirm", "createConfirm", "isNew", "cell", "inputClass", "mode", "isInEditing"], outputs: ["edited"] }, { kind: "component", type: ActionsComponent, selector: "ng2-st-actions", inputs: ["grid"], outputs: ["create"] }] });
2427
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadFormRowComponent, decorators: [{
2428
- type: Component,
2429
- args: [{
2430
- selector: '[ng2-st-thead-form-row]',
2431
- template: `
2432
- <td *ngIf="grid.isMultiSelectVisible"></td>
2433
- <td *ngIf="showActionColumnLeft" class="ng2-smart-actions">
2434
- <ng2-st-actions [grid]="grid" (create)="onCreate($event)"></ng2-st-actions>
2435
- </td>
2436
- <td *ngFor="let cell of getVisibleCells(grid.getNewRow().getCells())">
2437
- <ng2-smart-table-cell [cell]="cell"
2438
- [grid]="grid"
2439
- [isNew]="true"
2440
- [createConfirm]="createConfirm"
2441
- [inputClass]="addInputClass"
2442
- [isInEditing]="grid.getNewRow().isInEditing"
2443
- (edited)="onCreate($event)">
2444
- </ng2-smart-table-cell>
2445
- </td>
2446
- <td *ngIf="showActionColumnRight" class="ng2-smart-actions">
2447
- <ng2-st-actions [grid]="grid" (create)="onCreate($event)"></ng2-st-actions>
2448
- </td>
2449
- `,
2258
+ TbodyCustomComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyCustomComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2259
+ TbodyCustomComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TbodyCustomComponent, selector: "ng2-st-tbody-custom", inputs: { grid: "grid", row: "row", source: "source" }, outputs: { custom: "custom" }, ngImport: i0, template: `
2260
+ <a *ngFor="let action of grid.getSetting('actions.custom')" href="#"
2261
+ class="ng2-smart-action ng2-smart-action-custom-custom"
2262
+ [innerHTML]="action.title"
2263
+ (click)="onCustom(action, $event)"></a>
2264
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2265
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TbodyCustomComponent, decorators: [{
2266
+ type: Component,
2267
+ args: [{
2268
+ selector: 'ng2-st-tbody-custom',
2269
+ changeDetection: ChangeDetectionStrategy.OnPush,
2270
+ template: `
2271
+ <a *ngFor="let action of grid.getSetting('actions.custom')" href="#"
2272
+ class="ng2-smart-action ng2-smart-action-custom-custom"
2273
+ [innerHTML]="action.title"
2274
+ (click)="onCustom(action, $event)"></a>
2275
+ `
2450
2276
  }]
2451
2277
  }], propDecorators: { grid: [{
2452
2278
  type: Input
2453
2279
  }], row: [{
2454
2280
  type: Input
2455
- }], createConfirm: [{
2281
+ }], source: [{
2456
2282
  type: Input
2457
- }], create: [{
2283
+ }], custom: [{
2458
2284
  type: Output
2459
2285
  }] } });
2460
2286
 
2461
- class ActionsTitleComponent {
2462
- constructor(ref) {
2463
- this.ref = ref;
2287
+ class Ng2SmartTableTbodyComponent {
2288
+ constructor() {
2289
+ this.rowClassFunction = () => '';
2290
+ this.save = new EventEmitter();
2291
+ this.cancel = new EventEmitter();
2292
+ this.edit = new EventEmitter();
2293
+ this.editCancel = new EventEmitter();
2294
+ this.delete = new EventEmitter();
2295
+ this.custom = new EventEmitter();
2296
+ this.edited = new EventEmitter();
2297
+ this.userSelectRow = new EventEmitter();
2298
+ this.userClickedRow = new EventEmitter();
2299
+ this.editRowSelect = new EventEmitter();
2300
+ this.multipleSelectRow = new EventEmitter();
2301
+ this.isMultiSelectVisible = false;
2302
+ this.showActionColumnLeft = false;
2303
+ this.showActionColumnRight = false;
2304
+ this.mode = 'inline';
2305
+ this.editInputClass = '';
2306
+ this.isActionAdd = false;
2307
+ this.isActionEdit = false;
2308
+ this.isActionDelete = false;
2309
+ this.noDataMessage = false;
2464
2310
  }
2465
- ngAfterViewInit() {
2466
- this.ref.nativeElement.classList.add('ng2-smart-actions');
2311
+ get tableColumnsCount() {
2312
+ const actionColumns = this.isActionAdd || this.isActionEdit || this.isActionDelete ? 1 : 0;
2313
+ return this.grid.getColumns().length + actionColumns;
2467
2314
  }
2468
2315
  ngOnChanges() {
2469
- this.actionsColumnTitle = this.grid.getSetting('actions.columnTitle');
2316
+ this.isMultiSelectVisible = this.grid.isMultiSelectVisible();
2317
+ this.showActionColumnLeft = this.grid.showActionColumn('left');
2318
+ this.mode = this.grid.getSetting('mode', 'inline');
2319
+ this.editInputClass = this.grid.getSetting('edit.inputClass', '');
2320
+ this.showActionColumnRight = this.grid.showActionColumn('right');
2321
+ this.isActionAdd = this.grid.getSetting('actions.add', false);
2322
+ this.isActionEdit = this.grid.getSetting('actions.edit', false);
2323
+ this.isActionDelete = this.grid.getSetting('actions.delete', false);
2324
+ this.noDataMessage = this.grid.getSetting('noDataMessage');
2325
+ }
2326
+ getVisibleCells(cells) {
2327
+ return (cells || []).filter((cell) => !cell.getColumn().hide);
2328
+ }
2329
+ trackByIdOrIndex(index, item) {
2330
+ return item?.id || index;
2470
2331
  }
2471
2332
  }
2472
- ActionsTitleComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionsTitleComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
2473
- ActionsTitleComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: ActionsTitleComponent, selector: "[ng2-st-actions-title]", inputs: { grid: "grid" }, usesOnChanges: true, ngImport: i0, template: `
2474
- <div class="ng2-smart-title">{{ actionsColumnTitle }}</div>
2475
- `, isInline: true });
2476
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionsTitleComponent, decorators: [{
2333
+ Ng2SmartTableTbodyComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: Ng2SmartTableTbodyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2334
+ Ng2SmartTableTbodyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: Ng2SmartTableTbodyComponent, selector: "[ng2-st-tbody]", inputs: { grid: "grid", source: "source", deleteConfirm: "deleteConfirm", editConfirm: "editConfirm", rowClassFunction: "rowClassFunction" }, outputs: { save: "save", cancel: "cancel", edit: "edit", editCancel: "editCancel", delete: "delete", custom: "custom", edited: "edited", userSelectRow: "userSelectRow", userClickedRow: "userClickedRow", editRowSelect: "editRowSelect", multipleSelectRow: "multipleSelectRow" }, usesOnChanges: true, ngImport: i0, template: "<tr *ngFor=\"let row of grid.getRows(); trackBy: trackByIdOrIndex\" (click)=\"userClickedRow.emit(row)\" class=\"ng2-smart-row\" [className]=\"rowClassFunction(row)\" [ngClass]=\"{selected: row.isSelected}\">\n <td *ngIf=\"isMultiSelectVisible\" class=\"ng2-smart-actions ng2-smart-action-multiple-select\" (click)=\"multipleSelectRow.emit(row); $event.stopPropagation();\">\n <input type=\"checkbox\" class=\"form-control\" [ngModel]=\"row.isSelected\">\n </td>\n <td *ngIf=\"!row.isInEditing && showActionColumnLeft\" class=\"ng2-smart-actions\" (click)=\"$event.stopPropagation()\">\n <ng2-st-tbody-custom [grid]=\"grid\" (custom)=\"custom.emit($event)\" [row]=\"row\" [source]=\"source\"></ng2-st-tbody-custom>\n\n <ng2-st-tbody-edit-delete [grid]=\"grid\"\n [deleteConfirm]=\"deleteConfirm\"\n [editConfirm]=\"editConfirm\"\n (edit)=\"edit.emit(row)\"\n (delete)=\"delete.emit(row)\"\n (editRowSelect)=\"editRowSelect.emit($event)\"\n [row]=\"row\"\n [source]=\"source\">\n </ng2-st-tbody-edit-delete>\n </td>\n <td *ngIf=\"row.isInEditing && showActionColumnLeft\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-create-cancel [grid]=\"grid\" [row]=\"row\" [editConfirm]=\"editConfirm\" [editCancel]=\"editCancel\"></ng2-st-tbody-create-cancel>\n </td>\n <td *ngFor=\"let cell of getVisibleCells(row.cells)\">\n <ng2-smart-table-cell [cell]=\"cell\"\n [grid]=\"grid\"\n [row]=\"row\"\n [isNew]=\"false\"\n [mode]=\"mode\"\n [editConfirm]=\"editConfirm\"\n [inputClass]=\"editInputClass\"\n [isInEditing]=\"row.isInEditing\">\n </ng2-smart-table-cell>\n </td>\n\n <td *ngIf=\"row.isInEditing && showActionColumnRight\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-create-cancel [grid]=\"grid\" [row]=\"row\" [editConfirm]=\"editConfirm\"></ng2-st-tbody-create-cancel>\n </td>\n\n <td *ngIf=\"!row.isInEditing && showActionColumnRight\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-custom [grid]=\"grid\" (custom)=\"custom.emit($event)\" [row]=\"row\" [source]=\"source\"></ng2-st-tbody-custom>\n\n <ng2-st-tbody-edit-delete [grid]=\"grid\"\n [deleteConfirm]=\"deleteConfirm\"\n [editConfirm]=\"editConfirm\"\n [row]=\"row\"\n [source]=\"source\"\n (edit)=\"edit.emit(row)\"\n (delete)=\"delete.emit(row)\"\n (editRowSelect)=\"editRowSelect.emit($event)\">\n </ng2-st-tbody-edit-delete>\n </td>\n</tr>\n\n<tr *ngIf=\"grid.getRows().length == 0\">\n <td [attr.colspan]=\"tableColumnsCount\">\n {{ noDataMessage }}\n </td>\n</tr>\n", styles: [":host .ng2-smart-row.selected{background:rgba(0,0,0,.05)}:host .ng2-smart-row .ng2-smart-actions.ng2-smart-action-multiple-select{text-align:center}:host ::ng-deep ng2-st-tbody-edit-delete a:first-child,:host ::ng-deep ng2-st-tbody-create-cancel a:first-child{margin-right:.25rem}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: CellComponent, selector: "ng2-smart-table-cell", inputs: ["grid", "row", "editConfirm", "createConfirm", "isNew", "cell", "inputClass", "mode", "isInEditing"], outputs: ["edited"] }, { kind: "component", type: TbodyCreateCancelComponent, selector: "ng2-st-tbody-create-cancel", inputs: ["grid", "row", "editConfirm", "editCancel"] }, { kind: "component", type: TbodyEditDeleteComponent, selector: "ng2-st-tbody-edit-delete", inputs: ["grid", "row", "source", "deleteConfirm", "editConfirm"], outputs: ["edit", "delete", "editRowSelect"] }, { kind: "component", type: TbodyCustomComponent, selector: "ng2-st-tbody-custom", inputs: ["grid", "row", "source"], outputs: ["custom"] }] });
2335
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: Ng2SmartTableTbodyComponent, decorators: [{
2477
2336
  type: Component,
2478
- args: [{
2479
- selector: '[ng2-st-actions-title]',
2480
- template: `
2481
- <div class="ng2-smart-title">{{ actionsColumnTitle }}</div>
2482
- `,
2483
- }]
2484
- }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { grid: [{
2337
+ args: [{ selector: '[ng2-st-tbody]', template: "<tr *ngFor=\"let row of grid.getRows(); trackBy: trackByIdOrIndex\" (click)=\"userClickedRow.emit(row)\" class=\"ng2-smart-row\" [className]=\"rowClassFunction(row)\" [ngClass]=\"{selected: row.isSelected}\">\n <td *ngIf=\"isMultiSelectVisible\" class=\"ng2-smart-actions ng2-smart-action-multiple-select\" (click)=\"multipleSelectRow.emit(row); $event.stopPropagation();\">\n <input type=\"checkbox\" class=\"form-control\" [ngModel]=\"row.isSelected\">\n </td>\n <td *ngIf=\"!row.isInEditing && showActionColumnLeft\" class=\"ng2-smart-actions\" (click)=\"$event.stopPropagation()\">\n <ng2-st-tbody-custom [grid]=\"grid\" (custom)=\"custom.emit($event)\" [row]=\"row\" [source]=\"source\"></ng2-st-tbody-custom>\n\n <ng2-st-tbody-edit-delete [grid]=\"grid\"\n [deleteConfirm]=\"deleteConfirm\"\n [editConfirm]=\"editConfirm\"\n (edit)=\"edit.emit(row)\"\n (delete)=\"delete.emit(row)\"\n (editRowSelect)=\"editRowSelect.emit($event)\"\n [row]=\"row\"\n [source]=\"source\">\n </ng2-st-tbody-edit-delete>\n </td>\n <td *ngIf=\"row.isInEditing && showActionColumnLeft\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-create-cancel [grid]=\"grid\" [row]=\"row\" [editConfirm]=\"editConfirm\" [editCancel]=\"editCancel\"></ng2-st-tbody-create-cancel>\n </td>\n <td *ngFor=\"let cell of getVisibleCells(row.cells)\">\n <ng2-smart-table-cell [cell]=\"cell\"\n [grid]=\"grid\"\n [row]=\"row\"\n [isNew]=\"false\"\n [mode]=\"mode\"\n [editConfirm]=\"editConfirm\"\n [inputClass]=\"editInputClass\"\n [isInEditing]=\"row.isInEditing\">\n </ng2-smart-table-cell>\n </td>\n\n <td *ngIf=\"row.isInEditing && showActionColumnRight\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-create-cancel [grid]=\"grid\" [row]=\"row\" [editConfirm]=\"editConfirm\"></ng2-st-tbody-create-cancel>\n </td>\n\n <td *ngIf=\"!row.isInEditing && showActionColumnRight\" class=\"ng2-smart-actions\">\n <ng2-st-tbody-custom [grid]=\"grid\" (custom)=\"custom.emit($event)\" [row]=\"row\" [source]=\"source\"></ng2-st-tbody-custom>\n\n <ng2-st-tbody-edit-delete [grid]=\"grid\"\n [deleteConfirm]=\"deleteConfirm\"\n [editConfirm]=\"editConfirm\"\n [row]=\"row\"\n [source]=\"source\"\n (edit)=\"edit.emit(row)\"\n (delete)=\"delete.emit(row)\"\n (editRowSelect)=\"editRowSelect.emit($event)\">\n </ng2-st-tbody-edit-delete>\n </td>\n</tr>\n\n<tr *ngIf=\"grid.getRows().length == 0\">\n <td [attr.colspan]=\"tableColumnsCount\">\n {{ noDataMessage }}\n </td>\n</tr>\n", styles: [":host .ng2-smart-row.selected{background:rgba(0,0,0,.05)}:host .ng2-smart-row .ng2-smart-actions.ng2-smart-action-multiple-select{text-align:center}:host ::ng-deep ng2-st-tbody-edit-delete a:first-child,:host ::ng-deep ng2-st-tbody-create-cancel a:first-child{margin-right:.25rem}\n"] }]
2338
+ }], propDecorators: { grid: [{
2339
+ type: Input
2340
+ }], source: [{
2341
+ type: Input
2342
+ }], deleteConfirm: [{
2343
+ type: Input
2344
+ }], editConfirm: [{
2485
2345
  type: Input
2346
+ }], rowClassFunction: [{
2347
+ type: Input
2348
+ }], save: [{
2349
+ type: Output
2350
+ }], cancel: [{
2351
+ type: Output
2352
+ }], edit: [{
2353
+ type: Output
2354
+ }], editCancel: [{
2355
+ type: Output
2356
+ }], delete: [{
2357
+ type: Output
2358
+ }], custom: [{
2359
+ type: Output
2360
+ }], edited: [{
2361
+ type: Output
2362
+ }], userSelectRow: [{
2363
+ type: Output
2364
+ }], userClickedRow: [{
2365
+ type: Output
2366
+ }], editRowSelect: [{
2367
+ type: Output
2368
+ }], multipleSelectRow: [{
2369
+ type: Output
2486
2370
  }] } });
2487
2371
 
2488
- class CheckboxSelectAllComponent {
2372
+ const TBODY_COMPONENTS = [
2373
+ TbodyCreateCancelComponent,
2374
+ TbodyEditDeleteComponent,
2375
+ TbodyCustomComponent,
2376
+ Ng2SmartTableTbodyComponent
2377
+ ];
2378
+ class TBodyModule {
2489
2379
  }
2490
- CheckboxSelectAllComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CheckboxSelectAllComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2491
- CheckboxSelectAllComponentcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: CheckboxSelectAllComponent, selector: "[ng2-st-checkbox-select-all]", inputs: { grid: "grid", source: "source" }, ngImport: i0, template: `
2492
- <input type="checkbox" [ngModel]="this.grid.dataSet.isAllSelected">
2493
- `, isInline: true, dependencies: [{ kind: "directive", type: i2.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
2494
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CheckboxSelectAllComponent, decorators: [{
2495
- type: Component,
2380
+ TBodyModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TBodyModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2381
+ TBodyModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: TBodyModule, declarations: [TbodyCreateCancelComponent,
2382
+ TbodyEditDeleteComponent,
2383
+ TbodyCustomComponent,
2384
+ Ng2SmartTableTbodyComponent], imports: [CommonModule,
2385
+ FormsModule,
2386
+ CellModule], exports: [TbodyCreateCancelComponent,
2387
+ TbodyEditDeleteComponent,
2388
+ TbodyCustomComponent,
2389
+ Ng2SmartTableTbodyComponent] });
2390
+ TBodyModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TBodyModule, imports: [CommonModule,
2391
+ FormsModule,
2392
+ CellModule] });
2393
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TBodyModule, decorators: [{
2394
+ type: NgModule,
2496
2395
  args: [{
2497
- selector: '[ng2-st-checkbox-select-all]',
2498
- template: `
2499
- <input type="checkbox" [ngModel]="this.grid.dataSet.isAllSelected">
2500
- `,
2396
+ imports: [
2397
+ CommonModule,
2398
+ FormsModule,
2399
+ CellModule,
2400
+ ],
2401
+ declarations: [
2402
+ ...TBODY_COMPONENTS,
2403
+ ],
2404
+ exports: [
2405
+ ...TBODY_COMPONENTS,
2406
+ ],
2501
2407
  }]
2502
- }], propDecorators: { grid: [{
2503
- type: Input
2504
- }], source: [{
2505
- type: Input
2506
- }] } });
2408
+ }] });
2507
2409
 
2508
- class TitleComponent {
2509
- constructor() {
2510
- this.currentDirection = '';
2511
- this.sort = new EventEmitter();
2410
+ class AddButtonComponent {
2411
+ constructor(ref) {
2412
+ this.ref = ref;
2413
+ this.create = new EventEmitter();
2414
+ this.isActionAdd = false;
2415
+ this.addNewButtonContent = '';
2512
2416
  }
2513
- ngOnChanges(changes) {
2514
- if (changes.source) {
2515
- if (!changes.source.firstChange) {
2516
- this.dataChangedSub.unsubscribe();
2517
- }
2518
- this.dataChangedSub = this.source.onChanged().subscribe((dataChanges) => {
2519
- const sortConf = this.source.getSort();
2520
- if (sortConf.length > 0 && sortConf[0]['field'] === this.column.id) {
2521
- this.currentDirection = sortConf[0]['direction'];
2522
- }
2523
- else {
2524
- this.currentDirection = '';
2525
- }
2526
- sortConf.forEach((fieldConf) => {
2527
- });
2528
- });
2529
- }
2417
+ ngAfterViewInit() {
2418
+ this.ref.nativeElement.classList.add('ng2-smart-actions-title', 'ng2-smart-actions-title-add');
2530
2419
  }
2531
- _sort(event) {
2532
- event.preventDefault();
2533
- this.changeSortDirection();
2534
- this.source.setSort([
2535
- {
2536
- field: this.column.id,
2537
- direction: this.currentDirection,
2538
- compare: this.column.getCompareFunction(),
2539
- },
2540
- ]);
2541
- this.sort.emit(null);
2420
+ ngOnChanges() {
2421
+ this.isActionAdd = this.grid.getSetting('actions.add');
2422
+ this.addNewButtonContent = this.grid.getSetting('add.addButtonContent');
2542
2423
  }
2543
- changeSortDirection() {
2544
- if (this.currentDirection) {
2545
- const newDirection = this.currentDirection === 'asc' ? 'desc' : 'asc';
2546
- this.currentDirection = newDirection;
2424
+ onAdd(event) {
2425
+ event.preventDefault();
2426
+ event.stopPropagation();
2427
+ if (this.grid.getSetting('mode') === 'external') {
2428
+ this.create.emit({
2429
+ source: this.source,
2430
+ });
2547
2431
  }
2548
2432
  else {
2549
- this.currentDirection = this.column.sortDirection;
2433
+ this.grid.createFormShown = true;
2550
2434
  }
2551
- return this.currentDirection;
2552
- }
2553
- }
2554
- TitleComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TitleComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2555
- TitleComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TitleComponent, selector: "ng2-smart-table-title", inputs: { column: "column", source: "source" }, outputs: { sort: "sort" }, usesOnChanges: true, ngImport: i0, template: `
2556
- <a href="#" *ngIf="column.isSortable"
2557
- (click)="_sort($event)"
2558
- class="ng2-smart-sort-link sort"
2559
- [ngClass]="currentDirection">
2560
- {{ column.title }}
2561
- </a>
2562
- <span class="ng2-smart-sort" *ngIf="!column.isSortable">{{ column.title }}</span>
2563
- `, isInline: true, styles: ["a.sort.asc,a.sort.desc{font-weight:700}a.sort.asc:after,a.sort.desc:after{content:\"\";display:inline-block;width:0;height:0;border-bottom:4px solid rgba(0,0,0,.3);border-top:4px solid transparent;border-left:4px solid transparent;border-right:4px solid transparent;margin-bottom:2px}a.sort.desc:after{transform:rotate(-180deg);margin-bottom:-2px}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
2564
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TitleComponent, decorators: [{
2565
- type: Component,
2566
- args: [{ selector: 'ng2-smart-table-title', template: `
2567
- <a href="#" *ngIf="column.isSortable"
2568
- (click)="_sort($event)"
2569
- class="ng2-smart-sort-link sort"
2570
- [ngClass]="currentDirection">
2571
- {{ column.title }}
2572
- </a>
2573
- <span class="ng2-smart-sort" *ngIf="!column.isSortable">{{ column.title }}</span>
2574
- `, styles: ["a.sort.asc,a.sort.desc{font-weight:700}a.sort.asc:after,a.sort.desc:after{content:\"\";display:inline-block;width:0;height:0;border-bottom:4px solid rgba(0,0,0,.3);border-top:4px solid transparent;border-left:4px solid transparent;border-right:4px solid transparent;margin-bottom:2px}a.sort.desc:after{transform:rotate(-180deg);margin-bottom:-2px}\n"] }]
2575
- }], propDecorators: { column: [{
2576
- type: Input
2577
- }], source: [{
2578
- type: Input
2579
- }], sort: [{
2580
- type: Output
2581
- }] } });
2582
-
2583
- class ColumnTitleComponent {
2584
- constructor() {
2585
- this.sort = new EventEmitter();
2586
2435
  }
2587
2436
  }
2588
- ColumnTitleComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ColumnTitleComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2589
- ColumnTitleComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: ColumnTitleComponent, selector: "ng2-st-column-title", inputs: { column: "column", source: "source" }, outputs: { sort: "sort" }, ngImport: i0, template: `
2590
- <div class="ng2-smart-title">
2591
- <ng2-smart-table-title [source]="source" [column]="column" (sort)="sort.emit($event)"></ng2-smart-table-title>
2592
- </div>
2593
- `, isInline: true, dependencies: [{ kind: "component", type: TitleComponent, selector: "ng2-smart-table-title", inputs: ["column", "source"], outputs: ["sort"] }] });
2594
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ColumnTitleComponent, decorators: [{
2437
+ AddButtonComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AddButtonComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
2438
+ AddButtonComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: AddButtonComponent, selector: "[ng2-st-add-button]", inputs: { grid: "grid", source: "source" }, outputs: { create: "create" }, usesOnChanges: true, ngImport: i0, template: `
2439
+ <a *ngIf="isActionAdd" href="#" class="ng2-smart-action ng2-smart-action-add-add"
2440
+ [innerHTML]="addNewButtonContent" (click)="onAdd($event)"></a>
2441
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
2442
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AddButtonComponent, decorators: [{
2595
2443
  type: Component,
2596
2444
  args: [{
2597
- selector: 'ng2-st-column-title',
2445
+ selector: '[ng2-st-add-button]',
2598
2446
  template: `
2599
- <div class="ng2-smart-title">
2600
- <ng2-smart-table-title [source]="source" [column]="column" (sort)="sort.emit($event)"></ng2-smart-table-title>
2601
- </div>
2447
+ <a *ngIf="isActionAdd" href="#" class="ng2-smart-action ng2-smart-action-add-add"
2448
+ [innerHTML]="addNewButtonContent" (click)="onAdd($event)"></a>
2602
2449
  `,
2603
2450
  }]
2604
- }], propDecorators: { column: [{
2451
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { grid: [{
2605
2452
  type: Input
2606
2453
  }], source: [{
2607
2454
  type: Input
2608
- }], sort: [{
2455
+ }], create: [{
2609
2456
  type: Output
2610
2457
  }] } });
2611
2458
 
2612
- class TheadTitlesRowComponent {
2459
+ class TheadFitlersRowComponent {
2613
2460
  constructor() {
2614
- this.sort = new EventEmitter();
2615
- this.selectAllRows = new EventEmitter();
2461
+ this.create = new EventEmitter();
2462
+ this.filter = new EventEmitter();
2463
+ this.isMultiSelectVisible = false;
2464
+ this.showActionColumnLeft = false;
2465
+ this.showActionColumnRight = false;
2466
+ this.filterInputClass = '';
2616
2467
  }
2617
2468
  ngOnChanges() {
2618
2469
  this.isMultiSelectVisible = this.grid.isMultiSelectVisible();
2619
2470
  this.showActionColumnLeft = this.grid.showActionColumn('left');
2620
2471
  this.showActionColumnRight = this.grid.showActionColumn('right');
2472
+ this.filterInputClass = this.grid.getSetting('filter.inputClass', '');
2621
2473
  }
2622
2474
  getVisibleColumns(columns) {
2623
2475
  return (columns || []).filter((column) => !column.hide);
2624
2476
  }
2625
2477
  }
2626
- TheadTitlesRowComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadTitlesRowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2627
- TheadTitlesRowComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TheadTitlesRowComponent, selector: "[ng2-st-thead-titles-row]", inputs: { grid: "grid", source: "source" }, outputs: { sort: "sort", selectAllRows: "selectAllRows" }, usesOnChanges: true, ngImport: i0, template: `
2628
- <th ng2-st-checkbox-select-all *ngIf="isMultiSelectVisible"
2629
- [grid]="grid"
2630
- [source]="source"
2631
- (click)="selectAllRows.emit($event)">
2478
+ TheadFitlersRowComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadFitlersRowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2479
+ TheadFitlersRowComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TheadFitlersRowComponent, selector: "[ng2-st-thead-filters-row]", inputs: { grid: "grid", source: "source" }, outputs: { create: "create", filter: "filter" }, usesOnChanges: true, ngImport: i0, template: `
2480
+ <th *ngIf="isMultiSelectVisible"></th>
2481
+ <th ng2-st-add-button *ngIf="showActionColumnLeft"
2482
+ [grid]="grid"
2483
+ (create)="create.emit($event)">
2632
2484
  </th>
2633
- <th ng2-st-actions-title *ngIf="showActionColumnLeft" [grid]="grid"></th>
2634
- <th *ngFor="let column of getVisibleColumns(grid.getColumns())"
2635
- class="ng2-smart-th {{ column.id }}"
2636
- [ngClass]="column.class"
2637
- [style.width]="column.width">
2638
- <ng2-st-column-title [source]="source" [column]="column" (sort)="sort.emit($event)"></ng2-st-column-title>
2485
+ <th *ngFor="let column of getVisibleColumns(grid.getColumns())" class="ng2-smart-th {{ column.id }}">
2486
+ <ng2-smart-table-filter [source]="source"
2487
+ [column]="column"
2488
+ [inputClass]="filterInputClass"
2489
+ (filter)="filter.emit($event)">
2490
+ </ng2-smart-table-filter>
2639
2491
  </th>
2640
- <th ng2-st-actions-title *ngIf="showActionColumnRight" [grid]="grid"></th>
2641
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: ActionsTitleComponent, selector: "[ng2-st-actions-title]", inputs: ["grid"] }, { kind: "component", type: CheckboxSelectAllComponent, selector: "[ng2-st-checkbox-select-all]", inputs: ["grid", "source"] }, { kind: "component", type: ColumnTitleComponent, selector: "ng2-st-column-title", inputs: ["column", "source"], outputs: ["sort"] }] });
2642
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadTitlesRowComponent, decorators: [{
2492
+ <th ng2-st-add-button *ngIf="showActionColumnRight"
2493
+ [grid]="grid"
2494
+ [source]="source"
2495
+ (create)="create.emit($event)">
2496
+ </th>
2497
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: FilterComponent, selector: "ng2-smart-table-filter" }, { kind: "component", type: AddButtonComponent, selector: "[ng2-st-add-button]", inputs: ["grid", "source"], outputs: ["create"] }] });
2498
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadFitlersRowComponent, decorators: [{
2643
2499
  type: Component,
2644
2500
  args: [{
2645
- selector: '[ng2-st-thead-titles-row]',
2501
+ selector: '[ng2-st-thead-filters-row]',
2646
2502
  template: `
2647
- <th ng2-st-checkbox-select-all *ngIf="isMultiSelectVisible"
2648
- [grid]="grid"
2649
- [source]="source"
2650
- (click)="selectAllRows.emit($event)">
2503
+ <th *ngIf="isMultiSelectVisible"></th>
2504
+ <th ng2-st-add-button *ngIf="showActionColumnLeft"
2505
+ [grid]="grid"
2506
+ (create)="create.emit($event)">
2651
2507
  </th>
2652
- <th ng2-st-actions-title *ngIf="showActionColumnLeft" [grid]="grid"></th>
2653
- <th *ngFor="let column of getVisibleColumns(grid.getColumns())"
2654
- class="ng2-smart-th {{ column.id }}"
2655
- [ngClass]="column.class"
2656
- [style.width]="column.width">
2657
- <ng2-st-column-title [source]="source" [column]="column" (sort)="sort.emit($event)"></ng2-st-column-title>
2508
+ <th *ngFor="let column of getVisibleColumns(grid.getColumns())" class="ng2-smart-th {{ column.id }}">
2509
+ <ng2-smart-table-filter [source]="source"
2510
+ [column]="column"
2511
+ [inputClass]="filterInputClass"
2512
+ (filter)="filter.emit($event)">
2513
+ </ng2-smart-table-filter>
2514
+ </th>
2515
+ <th ng2-st-add-button *ngIf="showActionColumnRight"
2516
+ [grid]="grid"
2517
+ [source]="source"
2518
+ (create)="create.emit($event)">
2658
2519
  </th>
2659
- <th ng2-st-actions-title *ngIf="showActionColumnRight" [grid]="grid"></th>
2660
2520
  `,
2661
2521
  }]
2662
2522
  }], propDecorators: { grid: [{
2663
2523
  type: Input
2664
2524
  }], source: [{
2665
2525
  type: Input
2666
- }], sort: [{
2526
+ }], create: [{
2667
2527
  type: Output
2668
- }], selectAllRows: [{
2528
+ }], filter: [{
2669
2529
  type: Output
2670
2530
  }] } });
2671
2531
 
2672
- class Ng2SmartTableTheadComponent {
2532
+ class ActionsComponent {
2673
2533
  constructor() {
2674
- this.sort = new EventEmitter();
2675
- this.selectAllRows = new EventEmitter();
2676
2534
  this.create = new EventEmitter();
2677
- this.filter = new EventEmitter();
2535
+ this.createButtonContent = '';
2536
+ this.cancelButtonContent = '';
2678
2537
  }
2679
2538
  ngOnChanges() {
2680
- this.isHideHeader = this.grid.getSetting('hideHeader');
2681
- this.isHideSubHeader = this.grid.getSetting('hideSubHeader');
2539
+ this.createButtonContent = this.grid.getSetting('add.createButtonContent');
2540
+ this.cancelButtonContent = this.grid.getSetting('add.cancelButtonContent');
2682
2541
  }
2683
2542
  }
2684
- Ng2SmartTableTheadComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: Ng2SmartTableTheadComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2685
- Ng2SmartTableTheadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: Ng2SmartTableTheadComponent, selector: "[ng2-st-thead]", inputs: { grid: "grid", source: "source", createConfirm: "createConfirm" }, outputs: { sort: "sort", selectAllRows: "selectAllRows", create: "create", filter: "filter" }, usesOnChanges: true, ngImport: i0, template: "<tr ng2-st-thead-titles-row *ngIf=\"!isHideHeader\"\n class=\"ng2-smart-titles\"\n [grid]=\"grid\"\n [source]=\"source\"\n (sort)=\"sort.emit($event)\"\n (selectAllRows)=\"selectAllRows.emit($event)\">\n</tr>\n\n<tr ng2-st-thead-filters-row *ngIf=\"!isHideSubHeader\"\n class=\"ng2-smart-filters\"\n [grid]=\"grid\"\n [source]=\"source\"\n (create)=\"create.emit($event)\"\n (filter)=\"filter.emit($event)\">\n</tr>\n\n<tr ng2-st-thead-form-row *ngIf=\"grid.createFormShown\"\n [grid]=\"grid\"\n [createConfirm]=\"createConfirm\">\n</tr>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: TheadFitlersRowComponent, selector: "[ng2-st-thead-filters-row]", inputs: ["grid", "source"], outputs: ["create", "filter"] }, { kind: "component", type: TheadFormRowComponent, selector: "[ng2-st-thead-form-row]", inputs: ["grid", "row", "createConfirm"], outputs: ["create"] }, { kind: "component", type: TheadTitlesRowComponent, selector: "[ng2-st-thead-titles-row]", inputs: ["grid", "source"], outputs: ["sort", "selectAllRows"] }] });
2686
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: Ng2SmartTableTheadComponent, decorators: [{
2543
+ ActionsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2544
+ ActionsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: ActionsComponent, selector: "ng2-st-actions", inputs: { grid: "grid" }, outputs: { create: "create" }, usesOnChanges: true, ngImport: i0, template: `
2545
+ <a href="#" class="ng2-smart-action ng2-smart-action-add-create"
2546
+ [innerHTML]="createButtonContent"
2547
+ (click)="$event.preventDefault();create.emit($event)"></a>
2548
+ <a href="#" class="ng2-smart-action ng2-smart-action-add-cancel"
2549
+ [innerHTML]="cancelButtonContent"
2550
+ (click)="$event.preventDefault();grid.createFormShown = false;"></a>
2551
+ `, isInline: true });
2552
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionsComponent, decorators: [{
2687
2553
  type: Component,
2688
- args: [{ selector: '[ng2-st-thead]', template: "<tr ng2-st-thead-titles-row *ngIf=\"!isHideHeader\"\n class=\"ng2-smart-titles\"\n [grid]=\"grid\"\n [source]=\"source\"\n (sort)=\"sort.emit($event)\"\n (selectAllRows)=\"selectAllRows.emit($event)\">\n</tr>\n\n<tr ng2-st-thead-filters-row *ngIf=\"!isHideSubHeader\"\n class=\"ng2-smart-filters\"\n [grid]=\"grid\"\n [source]=\"source\"\n (create)=\"create.emit($event)\"\n (filter)=\"filter.emit($event)\">\n</tr>\n\n<tr ng2-st-thead-form-row *ngIf=\"grid.createFormShown\"\n [grid]=\"grid\"\n [createConfirm]=\"createConfirm\">\n</tr>\n" }]
2554
+ args: [{
2555
+ selector: 'ng2-st-actions',
2556
+ template: `
2557
+ <a href="#" class="ng2-smart-action ng2-smart-action-add-create"
2558
+ [innerHTML]="createButtonContent"
2559
+ (click)="$event.preventDefault();create.emit($event)"></a>
2560
+ <a href="#" class="ng2-smart-action ng2-smart-action-add-cancel"
2561
+ [innerHTML]="cancelButtonContent"
2562
+ (click)="$event.preventDefault();grid.createFormShown = false;"></a>
2563
+ `,
2564
+ }]
2689
2565
  }], propDecorators: { grid: [{
2690
2566
  type: Input
2691
- }], source: [{
2692
- type: Input
2693
- }], createConfirm: [{
2694
- type: Input
2695
- }], sort: [{
2696
- type: Output
2697
- }], selectAllRows: [{
2698
- type: Output
2699
2567
  }], create: [{
2700
2568
  type: Output
2701
- }], filter: [{
2702
- type: Output
2703
2569
  }] } });
2704
2570
 
2705
- const THEAD_COMPONENTS = [
2706
- ActionsComponent,
2707
- ActionsTitleComponent,
2708
- AddButtonComponent,
2709
- CheckboxSelectAllComponent,
2710
- ColumnTitleComponent,
2711
- TitleComponent,
2712
- TheadFitlersRowComponent,
2713
- TheadFormRowComponent,
2714
- TheadTitlesRowComponent,
2715
- Ng2SmartTableTheadComponent,
2716
- ];
2717
- class THeadModule {
2571
+ class TheadFormRowComponent {
2572
+ constructor() {
2573
+ this.create = new EventEmitter();
2574
+ this.isMultiSelectVisible = false;
2575
+ this.showActionColumnLeft = false;
2576
+ this.showActionColumnRight = false;
2577
+ this.addInputClass = '';
2578
+ }
2579
+ onCreate(event) {
2580
+ event.stopPropagation();
2581
+ this.grid.create(this.grid.getNewRow(), this.createConfirm);
2582
+ }
2583
+ ngOnChanges() {
2584
+ this.isMultiSelectVisible = this.grid.isMultiSelectVisible();
2585
+ this.showActionColumnLeft = this.grid.showActionColumn('left');
2586
+ this.showActionColumnRight = this.grid.showActionColumn('right');
2587
+ this.addInputClass = this.grid.getSetting('add.inputClass', '');
2588
+ }
2589
+ getVisibleCells(cells) {
2590
+ return (cells || []).filter((cell) => !cell.getColumn().hide);
2591
+ }
2718
2592
  }
2719
- THeadModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: THeadModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2720
- THeadModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: THeadModule, declarations: [ActionsComponent,
2721
- ActionsTitleComponent,
2722
- AddButtonComponent,
2723
- CheckboxSelectAllComponent,
2724
- ColumnTitleComponent,
2725
- TitleComponent,
2726
- TheadFitlersRowComponent,
2727
- TheadFormRowComponent,
2728
- TheadTitlesRowComponent,
2729
- Ng2SmartTableTheadComponent], imports: [CommonModule,
2730
- FormsModule,
2731
- FilterModule,
2732
- CellModule], exports: [ActionsComponent,
2733
- ActionsTitleComponent,
2734
- AddButtonComponent,
2735
- CheckboxSelectAllComponent,
2736
- ColumnTitleComponent,
2737
- TitleComponent,
2738
- TheadFitlersRowComponent,
2739
- TheadFormRowComponent,
2740
- TheadTitlesRowComponent,
2741
- Ng2SmartTableTheadComponent] });
2742
- THeadModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: THeadModule, imports: [CommonModule,
2743
- FormsModule,
2744
- FilterModule,
2745
- CellModule] });
2746
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: THeadModule, decorators: [{
2747
- type: NgModule,
2593
+ TheadFormRowComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadFormRowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2594
+ TheadFormRowComponentcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TheadFormRowComponent, selector: "[ng2-st-thead-form-row]", inputs: { grid: "grid", row: "row", createConfirm: "createConfirm" }, outputs: { create: "create" }, usesOnChanges: true, ngImport: i0, template: `
2595
+ <td *ngIf="grid.isMultiSelectVisible"></td>
2596
+ <td *ngIf="showActionColumnLeft" class="ng2-smart-actions">
2597
+ <ng2-st-actions [grid]="grid" (create)="onCreate($event)"></ng2-st-actions>
2598
+ </td>
2599
+ <td *ngFor="let cell of getVisibleCells(grid.getNewRow().getCells())">
2600
+ <ng2-smart-table-cell [cell]="cell"
2601
+ [grid]="grid"
2602
+ [isNew]="true"
2603
+ [createConfirm]="createConfirm"
2604
+ [inputClass]="addInputClass"
2605
+ [isInEditing]="grid.getNewRow().isInEditing"
2606
+ (edited)="onCreate($event)">
2607
+ </ng2-smart-table-cell>
2608
+ </td>
2609
+ <td *ngIf="showActionColumnRight" class="ng2-smart-actions">
2610
+ <ng2-st-actions [grid]="grid" (create)="onCreate($event)"></ng2-st-actions>
2611
+ </td>
2612
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: CellComponent, selector: "ng2-smart-table-cell", inputs: ["grid", "row", "editConfirm", "createConfirm", "isNew", "cell", "inputClass", "mode", "isInEditing"], outputs: ["edited"] }, { kind: "component", type: ActionsComponent, selector: "ng2-st-actions", inputs: ["grid"], outputs: ["create"] }] });
2613
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadFormRowComponent, decorators: [{
2614
+ type: Component,
2748
2615
  args: [{
2749
- imports: [
2750
- CommonModule,
2751
- FormsModule,
2752
- FilterModule,
2753
- CellModule,
2754
- ],
2755
- declarations: [
2756
- ...THEAD_COMPONENTS,
2757
- ],
2758
- exports: [
2759
- ...THEAD_COMPONENTS,
2760
- ],
2616
+ selector: '[ng2-st-thead-form-row]',
2617
+ template: `
2618
+ <td *ngIf="grid.isMultiSelectVisible"></td>
2619
+ <td *ngIf="showActionColumnLeft" class="ng2-smart-actions">
2620
+ <ng2-st-actions [grid]="grid" (create)="onCreate($event)"></ng2-st-actions>
2621
+ </td>
2622
+ <td *ngFor="let cell of getVisibleCells(grid.getNewRow().getCells())">
2623
+ <ng2-smart-table-cell [cell]="cell"
2624
+ [grid]="grid"
2625
+ [isNew]="true"
2626
+ [createConfirm]="createConfirm"
2627
+ [inputClass]="addInputClass"
2628
+ [isInEditing]="grid.getNewRow().isInEditing"
2629
+ (edited)="onCreate($event)">
2630
+ </ng2-smart-table-cell>
2631
+ </td>
2632
+ <td *ngIf="showActionColumnRight" class="ng2-smart-actions">
2633
+ <ng2-st-actions [grid]="grid" (create)="onCreate($event)"></ng2-st-actions>
2634
+ </td>
2635
+ `,
2761
2636
  }]
2762
- }] });
2637
+ }], propDecorators: { grid: [{
2638
+ type: Input
2639
+ }], row: [{
2640
+ type: Input
2641
+ }], createConfirm: [{
2642
+ type: Input
2643
+ }], create: [{
2644
+ type: Output
2645
+ }] } });
2763
2646
 
2764
- function compareValues(direction, a, b) {
2765
- if (a < b) {
2766
- return -1 * direction;
2767
- }
2768
- if (a > b) {
2769
- return direction;
2647
+ class ActionsTitleComponent {
2648
+ constructor(ref) {
2649
+ this.ref = ref;
2650
+ this.actionsColumnTitle = '';
2770
2651
  }
2771
- return 0;
2772
- }
2773
- class LocalSorter {
2774
- static sort(data, field, direction, customCompare) {
2775
- const dir = (direction === 'asc') ? 1 : -1;
2776
- const compare = customCompare ? customCompare : compareValues;
2777
- return data.sort((a, b) => {
2778
- return compare.call(null, dir, a[field], b[field]);
2779
- });
2652
+ ngAfterViewInit() {
2653
+ this.ref.nativeElement.classList.add('ng2-smart-actions');
2780
2654
  }
2781
- }
2782
-
2783
- function filterValues(value, search) {
2784
- return value.toString().toLowerCase().includes(search.toString().toLowerCase());
2785
- }
2786
- class LocalFilter {
2787
- static filter(data, field, search, customFilter) {
2788
- const filter = customFilter ? customFilter : filterValues;
2789
- return data.filter((el) => {
2790
- const value = typeof el[field] === 'undefined' || el[field] === null ? '' : el[field];
2791
- return filter.call(null, value, search);
2792
- });
2655
+ ngOnChanges() {
2656
+ this.actionsColumnTitle = this.grid.getSetting('actions.columnTitle');
2793
2657
  }
2794
2658
  }
2659
+ ActionsTitleComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionsTitleComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
2660
+ ActionsTitleComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: ActionsTitleComponent, selector: "[ng2-st-actions-title]", inputs: { grid: "grid" }, usesOnChanges: true, ngImport: i0, template: `
2661
+ <div class="ng2-smart-title">{{ actionsColumnTitle }}</div>
2662
+ `, isInline: true });
2663
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionsTitleComponent, decorators: [{
2664
+ type: Component,
2665
+ args: [{
2666
+ selector: '[ng2-st-actions-title]',
2667
+ template: `
2668
+ <div class="ng2-smart-title">{{ actionsColumnTitle }}</div>
2669
+ `,
2670
+ }]
2671
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { grid: [{
2672
+ type: Input
2673
+ }] } });
2795
2674
 
2796
- class LocalPager {
2797
- static paginate(data, page, perPage) {
2798
- return data.slice(perPage * (page - 1), perPage * page);
2799
- }
2675
+ class CheckboxSelectAllComponent {
2800
2676
  }
2677
+ CheckboxSelectAllComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CheckboxSelectAllComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2678
+ CheckboxSelectAllComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: CheckboxSelectAllComponent, selector: "[ng2-st-checkbox-select-all]", inputs: { grid: "grid", source: "source" }, ngImport: i0, template: `
2679
+ <input type="checkbox" [ngModel]="this.grid.dataSet.isAllSelected">
2680
+ `, isInline: true, dependencies: [{ kind: "directive", type: i2.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
2681
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CheckboxSelectAllComponent, decorators: [{
2682
+ type: Component,
2683
+ args: [{
2684
+ selector: '[ng2-st-checkbox-select-all]',
2685
+ template: `
2686
+ <input type="checkbox" [ngModel]="this.grid.dataSet.isAllSelected">
2687
+ `,
2688
+ }]
2689
+ }], propDecorators: { grid: [{
2690
+ type: Input
2691
+ }], source: [{
2692
+ type: Input
2693
+ }] } });
2801
2694
 
2802
- class LocalDataSource extends DataSource {
2803
- constructor(data = []) {
2804
- super();
2805
- this.data = [];
2806
- this.filteredAndSorted = [];
2807
- this.sortConf = [];
2808
- this.filterConf = {
2809
- filters: [],
2810
- andOperator: true,
2811
- };
2812
- this.pagingConf = {
2813
- page: 1,
2814
- perPage: 1,
2815
- };
2816
- this.data = data;
2817
- }
2818
- load(data) {
2819
- this.data = data;
2820
- return super.load(data);
2821
- }
2822
- prepend(element) {
2823
- this.reset(true);
2824
- this.data.unshift(element);
2825
- return super.prepend(element);
2826
- }
2827
- append(element) {
2828
- this.reset(true);
2829
- this.data.push(element);
2830
- return super.append(element);
2831
- }
2832
- add(element) {
2833
- this.data.push(element);
2834
- return super.add(element);
2835
- }
2836
- remove(element) {
2837
- this.data = this.data.filter(el => el !== element);
2838
- return super.remove(element);
2839
- }
2840
- update(element, values) {
2841
- return new Promise((resolve, reject) => {
2842
- this.find(element).then((found) => {
2843
- found = deepExtend(found, values);
2844
- super.update(found, values).then(resolve).catch(reject);
2845
- }).catch(reject);
2846
- });
2847
- }
2848
- find(element) {
2849
- const found = this.data.find(el => el === element);
2850
- if (found) {
2851
- return Promise.resolve(found);
2852
- }
2853
- return Promise.reject(new Error('Element was not found in the dataset'));
2854
- }
2855
- getElements() {
2856
- const data = this.data.slice(0);
2857
- return Promise.resolve(this.prepareData(data));
2858
- }
2859
- getFilteredAndSorted() {
2860
- let data = this.data.slice(0);
2861
- this.prepareData(data);
2862
- return Promise.resolve(this.filteredAndSorted);
2863
- }
2864
- getAll() {
2865
- const data = this.data.slice(0);
2866
- return Promise.resolve(data);
2867
- }
2868
- reset(silent = false) {
2869
- if (silent) {
2870
- this.filterConf = {
2871
- filters: [],
2872
- andOperator: true,
2873
- };
2874
- this.sortConf = [];
2875
- this.pagingConf.page = 1;
2876
- }
2877
- else {
2878
- this.setFilter([], true, false);
2879
- this.setSort([], false);
2880
- this.setPage(1);
2881
- }
2882
- }
2883
- empty() {
2884
- this.data = [];
2885
- return super.empty();
2886
- }
2887
- count() {
2888
- return this.filteredAndSorted.length;
2695
+ class TitleComponent {
2696
+ constructor() {
2697
+ this.currentDirection = '';
2698
+ this.sort = new EventEmitter();
2699
+ this.dataChangedSub = false;
2889
2700
  }
2890
- /**
2891
- *
2892
- * Array of conf objects
2893
- * [
2894
- * {field: string, direction: asc|desc|null, compare: Function|null},
2895
- * ]
2896
- * @param conf
2897
- * @param doEmit
2898
- * @returns {LocalDataSource}
2899
- */
2900
- setSort(conf, doEmit = true) {
2901
- if (conf !== null) {
2902
- conf.forEach((fieldConf) => {
2903
- if (!fieldConf.field || typeof fieldConf.direction === 'undefined') {
2904
- throw new Error('Sort configuration object is not valid');
2701
+ ngOnChanges(changes) {
2702
+ if (changes['source']) {
2703
+ if (!changes['source'].firstChange && this.dataChangedSub) {
2704
+ this.dataChangedSub.unsubscribe();
2705
+ }
2706
+ this.dataChangedSub = this.source.onChanged().subscribe((dataChanges) => {
2707
+ const sortConf = this.source.getSort();
2708
+ if (sortConf.length > 0 && sortConf[0]['field'] === this.column.id) {
2709
+ this.currentDirection = sortConf[0]['direction'];
2710
+ }
2711
+ else {
2712
+ this.currentDirection = '';
2905
2713
  }
2906
2714
  });
2907
- this.sortConf = conf;
2908
2715
  }
2909
- super.setSort(conf, doEmit);
2910
- return this;
2911
2716
  }
2912
- /**
2913
- *
2914
- * Array of conf objects
2915
- * [
2916
- * {field: string, search: string, filter: Function|null},
2917
- * ]
2918
- * @param conf
2919
- * @param andOperator
2920
- * @param doEmit
2921
- * @returns {LocalDataSource}
2922
- */
2923
- setFilter(conf, andOperator = true, doEmit = true) {
2924
- if (conf && conf.length > 0) {
2925
- conf.forEach((fieldConf) => {
2926
- this.addFilter(fieldConf, andOperator, false);
2927
- });
2928
- }
2929
- else {
2930
- this.filterConf = {
2931
- filters: [],
2932
- andOperator: true,
2933
- };
2934
- }
2935
- this.filterConf.andOperator = andOperator;
2936
- this.pagingConf.page = 1;
2937
- super.setFilter(conf, andOperator, doEmit);
2938
- return this;
2717
+ _sort(event) {
2718
+ event.preventDefault();
2719
+ this.changeSortDirection();
2720
+ this.source.setSort([
2721
+ {
2722
+ field: this.column.id,
2723
+ direction: this.currentDirection === 'desc' ? 'desc' : 'asc',
2724
+ compare: this.column.getCompareFunction(),
2725
+ },
2726
+ ]);
2727
+ this.sort.emit(null);
2939
2728
  }
2940
- addFilter(fieldConf, andOperator = true, doEmit = true) {
2941
- if (!fieldConf.field || typeof fieldConf.search === 'undefined') {
2942
- throw new Error('Filter configuration object is not valid');
2729
+ changeSortDirection() {
2730
+ if (this.currentDirection) {
2731
+ const newDirection = this.currentDirection === 'asc' ? 'desc' : 'asc';
2732
+ this.currentDirection = newDirection;
2943
2733
  }
2944
- let found = false;
2945
- this.filterConf.filters.forEach((currentFieldConf, index) => {
2946
- if (currentFieldConf.field === fieldConf.field) {
2947
- this.filterConf.filters[index] = fieldConf;
2948
- found = true;
2949
- }
2950
- });
2951
- if (!found) {
2952
- this.filterConf.filters.push(fieldConf);
2734
+ else {
2735
+ this.currentDirection = this.column.sortDirection;
2953
2736
  }
2954
- this.filterConf.andOperator = andOperator;
2955
- super.addFilter(fieldConf, andOperator, doEmit);
2956
- return this;
2957
- }
2958
- setPaging(page, perPage, doEmit = true) {
2959
- this.pagingConf.page = page;
2960
- this.pagingConf.perPage = perPage;
2961
- super.setPaging(page, perPage, doEmit);
2962
- return this;
2963
- }
2964
- setPage(page, doEmit = true) {
2965
- this.pagingConf.page = page;
2966
- super.setPage(page, doEmit);
2967
- return this;
2968
- }
2969
- getSort() {
2970
- return this.sortConf;
2737
+ return this.currentDirection;
2971
2738
  }
2972
- getFilter() {
2973
- return this.filterConf;
2739
+ }
2740
+ TitleComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TitleComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2741
+ TitleComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TitleComponent, selector: "ng2-smart-table-title", inputs: { column: "column", source: "source" }, outputs: { sort: "sort" }, usesOnChanges: true, ngImport: i0, template: `
2742
+ <a href="#" *ngIf="column.isSortable"
2743
+ (click)="_sort($event)"
2744
+ class="ng2-smart-sort-link sort"
2745
+ [ngClass]="currentDirection">
2746
+ {{ column.title }}
2747
+ </a>
2748
+ <span class="ng2-smart-sort" *ngIf="!column.isSortable">{{ column.title }}</span>
2749
+ `, isInline: true, styles: ["a.sort.asc,a.sort.desc{font-weight:700}a.sort.asc:after,a.sort.desc:after{content:\"\";display:inline-block;width:0;height:0;border-bottom:4px solid rgba(0,0,0,.3);border-top:4px solid transparent;border-left:4px solid transparent;border-right:4px solid transparent;margin-bottom:2px}a.sort.desc:after{transform:rotate(-180deg);margin-bottom:-2px}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
2750
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TitleComponent, decorators: [{
2751
+ type: Component,
2752
+ args: [{ selector: 'ng2-smart-table-title', template: `
2753
+ <a href="#" *ngIf="column.isSortable"
2754
+ (click)="_sort($event)"
2755
+ class="ng2-smart-sort-link sort"
2756
+ [ngClass]="currentDirection">
2757
+ {{ column.title }}
2758
+ </a>
2759
+ <span class="ng2-smart-sort" *ngIf="!column.isSortable">{{ column.title }}</span>
2760
+ `, styles: ["a.sort.asc,a.sort.desc{font-weight:700}a.sort.asc:after,a.sort.desc:after{content:\"\";display:inline-block;width:0;height:0;border-bottom:4px solid rgba(0,0,0,.3);border-top:4px solid transparent;border-left:4px solid transparent;border-right:4px solid transparent;margin-bottom:2px}a.sort.desc:after{transform:rotate(-180deg);margin-bottom:-2px}\n"] }]
2761
+ }], propDecorators: { column: [{
2762
+ type: Input
2763
+ }], source: [{
2764
+ type: Input
2765
+ }], sort: [{
2766
+ type: Output
2767
+ }] } });
2768
+
2769
+ class ColumnTitleComponent {
2770
+ constructor() {
2771
+ this.sort = new EventEmitter();
2974
2772
  }
2975
- getPaging() {
2976
- return this.pagingConf;
2773
+ }
2774
+ ColumnTitleComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ColumnTitleComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2775
+ ColumnTitleComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: ColumnTitleComponent, selector: "ng2-st-column-title", inputs: { column: "column", source: "source" }, outputs: { sort: "sort" }, ngImport: i0, template: `
2776
+ <div class="ng2-smart-title">
2777
+ <ng2-smart-table-title [source]="source" [column]="column" (sort)="sort.emit($event)"></ng2-smart-table-title>
2778
+ </div>
2779
+ `, isInline: true, dependencies: [{ kind: "component", type: TitleComponent, selector: "ng2-smart-table-title", inputs: ["column", "source"], outputs: ["sort"] }] });
2780
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ColumnTitleComponent, decorators: [{
2781
+ type: Component,
2782
+ args: [{
2783
+ selector: 'ng2-st-column-title',
2784
+ template: `
2785
+ <div class="ng2-smart-title">
2786
+ <ng2-smart-table-title [source]="source" [column]="column" (sort)="sort.emit($event)"></ng2-smart-table-title>
2787
+ </div>
2788
+ `,
2789
+ }]
2790
+ }], propDecorators: { column: [{
2791
+ type: Input
2792
+ }], source: [{
2793
+ type: Input
2794
+ }], sort: [{
2795
+ type: Output
2796
+ }] } });
2797
+
2798
+ class TheadTitlesRowComponent {
2799
+ constructor() {
2800
+ this.sort = new EventEmitter();
2801
+ this.selectAllRows = new EventEmitter();
2802
+ this.isMultiSelectVisible = false;
2803
+ this.showActionColumnLeft = false;
2804
+ this.showActionColumnRight = false;
2977
2805
  }
2978
- prepareData(data) {
2979
- data = this.filter(data);
2980
- data = this.sort(data);
2981
- this.filteredAndSorted = data.slice(0);
2982
- return this.paginate(data);
2806
+ ngOnChanges() {
2807
+ this.isMultiSelectVisible = this.grid.isMultiSelectVisible();
2808
+ this.showActionColumnLeft = this.grid.showActionColumn('left');
2809
+ this.showActionColumnRight = this.grid.showActionColumn('right');
2983
2810
  }
2984
- sort(data) {
2985
- if (this.sortConf) {
2986
- this.sortConf.forEach((fieldConf) => {
2987
- data = LocalSorter
2988
- .sort(data, fieldConf.field, fieldConf.direction, fieldConf.compare);
2989
- });
2990
- }
2991
- return data;
2811
+ getVisibleColumns(columns) {
2812
+ return (columns || []).filter((column) => !column.hide);
2992
2813
  }
2993
- // TODO: refactor?
2994
- filter(data) {
2995
- if (this.filterConf.filters) {
2996
- if (this.filterConf.andOperator) {
2997
- this.filterConf.filters.forEach((fieldConf) => {
2998
- if (fieldConf.search?.length > 0) {
2999
- data = LocalFilter
3000
- .filter(data, fieldConf.field, fieldConf.search, fieldConf.filter);
3001
- }
3002
- });
3003
- }
3004
- else {
3005
- let mergedData = [];
3006
- this.filterConf.filters.forEach((fieldConf) => {
3007
- if (fieldConf.search?.length > 0) {
3008
- mergedData = mergedData.concat(LocalFilter
3009
- .filter(data, fieldConf.field, fieldConf.search, fieldConf.filter));
3010
- }
3011
- });
3012
- // remove non unique items
3013
- data = mergedData.filter((elem, pos, arr) => {
3014
- return arr.indexOf(elem) === pos;
3015
- });
3016
- }
3017
- }
3018
- return data;
2814
+ }
2815
+ TheadTitlesRowComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadTitlesRowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2816
+ TheadTitlesRowComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: TheadTitlesRowComponent, selector: "[ng2-st-thead-titles-row]", inputs: { grid: "grid", source: "source" }, outputs: { sort: "sort", selectAllRows: "selectAllRows" }, usesOnChanges: true, ngImport: i0, template: `
2817
+ <th ng2-st-checkbox-select-all *ngIf="isMultiSelectVisible"
2818
+ [grid]="grid"
2819
+ [source]="source"
2820
+ (click)="selectAllRows.emit($event)">
2821
+ </th>
2822
+ <th ng2-st-actions-title *ngIf="showActionColumnLeft" [grid]="grid"></th>
2823
+ <th *ngFor="let column of getVisibleColumns(grid.getColumns())"
2824
+ class="ng2-smart-th {{ column.id }}"
2825
+ [ngClass]="column.class"
2826
+ [style.width]="column.width">
2827
+ <ng2-st-column-title [source]="source" [column]="column" (sort)="sort.emit($event)"></ng2-st-column-title>
2828
+ </th>
2829
+ <th ng2-st-actions-title *ngIf="showActionColumnRight" [grid]="grid"></th>
2830
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: ActionsTitleComponent, selector: "[ng2-st-actions-title]", inputs: ["grid"] }, { kind: "component", type: CheckboxSelectAllComponent, selector: "[ng2-st-checkbox-select-all]", inputs: ["grid", "source"] }, { kind: "component", type: ColumnTitleComponent, selector: "ng2-st-column-title", inputs: ["column", "source"], outputs: ["sort"] }] });
2831
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: TheadTitlesRowComponent, decorators: [{
2832
+ type: Component,
2833
+ args: [{
2834
+ selector: '[ng2-st-thead-titles-row]',
2835
+ template: `
2836
+ <th ng2-st-checkbox-select-all *ngIf="isMultiSelectVisible"
2837
+ [grid]="grid"
2838
+ [source]="source"
2839
+ (click)="selectAllRows.emit($event)">
2840
+ </th>
2841
+ <th ng2-st-actions-title *ngIf="showActionColumnLeft" [grid]="grid"></th>
2842
+ <th *ngFor="let column of getVisibleColumns(grid.getColumns())"
2843
+ class="ng2-smart-th {{ column.id }}"
2844
+ [ngClass]="column.class"
2845
+ [style.width]="column.width">
2846
+ <ng2-st-column-title [source]="source" [column]="column" (sort)="sort.emit($event)"></ng2-st-column-title>
2847
+ </th>
2848
+ <th ng2-st-actions-title *ngIf="showActionColumnRight" [grid]="grid"></th>
2849
+ `,
2850
+ }]
2851
+ }], propDecorators: { grid: [{
2852
+ type: Input
2853
+ }], source: [{
2854
+ type: Input
2855
+ }], sort: [{
2856
+ type: Output
2857
+ }], selectAllRows: [{
2858
+ type: Output
2859
+ }] } });
2860
+
2861
+ class Ng2SmartTableTheadComponent {
2862
+ constructor() {
2863
+ this.sort = new EventEmitter();
2864
+ this.selectAllRows = new EventEmitter();
2865
+ this.create = new EventEmitter();
2866
+ this.filter = new EventEmitter();
2867
+ this.isHideHeader = false;
2868
+ this.isHideSubHeader = false;
3019
2869
  }
3020
- paginate(data) {
3021
- if (this.pagingConf && this.pagingConf.page && this.pagingConf.perPage) {
3022
- data = LocalPager.paginate(data, this.pagingConf.page, this.pagingConf.perPage);
3023
- }
3024
- return data;
2870
+ ngOnChanges() {
2871
+ this.isHideHeader = this.grid.getSetting('hideHeader', false);
2872
+ this.isHideSubHeader = this.grid.getSetting('hideSubHeader', false);
3025
2873
  }
3026
2874
  }
2875
+ Ng2SmartTableTheadComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: Ng2SmartTableTheadComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2876
+ Ng2SmartTableTheadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: Ng2SmartTableTheadComponent, selector: "[ng2-st-thead]", inputs: { grid: "grid", source: "source", createConfirm: "createConfirm" }, outputs: { sort: "sort", selectAllRows: "selectAllRows", create: "create", filter: "filter" }, usesOnChanges: true, ngImport: i0, template: "<tr ng2-st-thead-titles-row *ngIf=\"!isHideHeader\"\n class=\"ng2-smart-titles\"\n [grid]=\"grid\"\n [source]=\"source\"\n (sort)=\"sort.emit($event)\"\n (selectAllRows)=\"selectAllRows.emit($event)\">\n</tr>\n\n<tr ng2-st-thead-filters-row *ngIf=\"!isHideSubHeader\"\n class=\"ng2-smart-filters\"\n [grid]=\"grid\"\n [source]=\"source\"\n (create)=\"create.emit($event)\"\n (filter)=\"filter.emit($event)\">\n</tr>\n\n<tr ng2-st-thead-form-row *ngIf=\"grid.createFormShown\"\n [grid]=\"grid\"\n [createConfirm]=\"createConfirm\">\n</tr>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: TheadFitlersRowComponent, selector: "[ng2-st-thead-filters-row]", inputs: ["grid", "source"], outputs: ["create", "filter"] }, { kind: "component", type: TheadFormRowComponent, selector: "[ng2-st-thead-form-row]", inputs: ["grid", "row", "createConfirm"], outputs: ["create"] }, { kind: "component", type: TheadTitlesRowComponent, selector: "[ng2-st-thead-titles-row]", inputs: ["grid", "source"], outputs: ["sort", "selectAllRows"] }] });
2877
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: Ng2SmartTableTheadComponent, decorators: [{
2878
+ type: Component,
2879
+ args: [{ selector: '[ng2-st-thead]', template: "<tr ng2-st-thead-titles-row *ngIf=\"!isHideHeader\"\n class=\"ng2-smart-titles\"\n [grid]=\"grid\"\n [source]=\"source\"\n (sort)=\"sort.emit($event)\"\n (selectAllRows)=\"selectAllRows.emit($event)\">\n</tr>\n\n<tr ng2-st-thead-filters-row *ngIf=\"!isHideSubHeader\"\n class=\"ng2-smart-filters\"\n [grid]=\"grid\"\n [source]=\"source\"\n (create)=\"create.emit($event)\"\n (filter)=\"filter.emit($event)\">\n</tr>\n\n<tr ng2-st-thead-form-row *ngIf=\"grid.createFormShown\"\n [grid]=\"grid\"\n [createConfirm]=\"createConfirm\">\n</tr>\n" }]
2880
+ }], propDecorators: { grid: [{
2881
+ type: Input
2882
+ }], source: [{
2883
+ type: Input
2884
+ }], createConfirm: [{
2885
+ type: Input
2886
+ }], sort: [{
2887
+ type: Output
2888
+ }], selectAllRows: [{
2889
+ type: Output
2890
+ }], create: [{
2891
+ type: Output
2892
+ }], filter: [{
2893
+ type: Output
2894
+ }] } });
2895
+
2896
+ const THEAD_COMPONENTS = [
2897
+ ActionsComponent,
2898
+ ActionsTitleComponent,
2899
+ AddButtonComponent,
2900
+ CheckboxSelectAllComponent,
2901
+ ColumnTitleComponent,
2902
+ TitleComponent,
2903
+ TheadFitlersRowComponent,
2904
+ TheadFormRowComponent,
2905
+ TheadTitlesRowComponent,
2906
+ Ng2SmartTableTheadComponent,
2907
+ ];
2908
+ class THeadModule {
2909
+ }
2910
+ THeadModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: THeadModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2911
+ THeadModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: THeadModule, declarations: [ActionsComponent,
2912
+ ActionsTitleComponent,
2913
+ AddButtonComponent,
2914
+ CheckboxSelectAllComponent,
2915
+ ColumnTitleComponent,
2916
+ TitleComponent,
2917
+ TheadFitlersRowComponent,
2918
+ TheadFormRowComponent,
2919
+ TheadTitlesRowComponent,
2920
+ Ng2SmartTableTheadComponent], imports: [CommonModule,
2921
+ FormsModule,
2922
+ FilterModule,
2923
+ CellModule], exports: [ActionsComponent,
2924
+ ActionsTitleComponent,
2925
+ AddButtonComponent,
2926
+ CheckboxSelectAllComponent,
2927
+ ColumnTitleComponent,
2928
+ TitleComponent,
2929
+ TheadFitlersRowComponent,
2930
+ TheadFormRowComponent,
2931
+ TheadTitlesRowComponent,
2932
+ Ng2SmartTableTheadComponent] });
2933
+ THeadModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: THeadModule, imports: [CommonModule,
2934
+ FormsModule,
2935
+ FilterModule,
2936
+ CellModule] });
2937
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: THeadModule, decorators: [{
2938
+ type: NgModule,
2939
+ args: [{
2940
+ imports: [
2941
+ CommonModule,
2942
+ FormsModule,
2943
+ FilterModule,
2944
+ CellModule,
2945
+ ],
2946
+ declarations: [
2947
+ ...THEAD_COMPONENTS,
2948
+ ],
2949
+ exports: [
2950
+ ...THEAD_COMPONENTS,
2951
+ ],
2952
+ }]
2953
+ }] });
3027
2954
 
3028
2955
  class Ng2SmartTableComponent {
3029
2956
  constructor() {
@@ -3038,15 +2965,17 @@ class Ng2SmartTableComponent {
3038
2965
  this.editConfirm = new EventEmitter();
3039
2966
  this.createConfirm = new EventEmitter();
3040
2967
  this.rowHover = new EventEmitter();
2968
+ this.tableClass = '';
2969
+ this.tableId = '';
2970
+ this.perPageSelect = [];
2971
+ this.isHideHeader = false;
2972
+ this.isHideSubHeader = false;
2973
+ this.isPagerDisplay = false;
2974
+ this.rowClassFunction = () => '';
3041
2975
  this.defaultSettings = {
3042
2976
  mode: 'inline',
3043
2977
  selectMode: 'single',
3044
- /**
3045
- * Points to an element in all data
3046
- *
3047
- * when < 0 all lines must be deselected
3048
- */
3049
- selectedRowIndex: 0,
2978
+ selectedRowIndex: -1,
3050
2979
  switchPageToSelectedRowPage: false,
3051
2980
  hideHeader: false,
3052
2981
  hideSubHeader: false,
@@ -3085,11 +3014,7 @@ class Ng2SmartTableComponent {
3085
3014
  },
3086
3015
  noDataMessage: 'No data found',
3087
3016
  columns: {},
3088
- pager: {
3089
- display: true,
3090
- page: 1,
3091
- perPage: 10,
3092
- },
3017
+ pager: false,
3093
3018
  rowClassFunction: () => '',
3094
3019
  };
3095
3020
  }
@@ -3110,10 +3035,9 @@ class Ng2SmartTableComponent {
3110
3035
  this.tableClass = this.grid.getSetting('attr.class');
3111
3036
  this.isHideHeader = this.grid.getSetting('hideHeader');
3112
3037
  this.isHideSubHeader = this.grid.getSetting('hideSubHeader');
3113
- this.isPagerDisplay = this.grid.getSetting('pager.display');
3114
- this.isPagerDisplay = this.grid.getSetting('pager.display');
3038
+ this.isPagerDisplay = this.grid.getSetting('pager.display', false);
3115
3039
  this.perPageSelect = this.grid.getSetting('pager.perPageSelect');
3116
- this.rowClassFunction = this.grid.getSetting('rowClassFunction');
3040
+ this.rowClassFunction = this.grid.getSetting('rowClassFunction', () => '');
3117
3041
  }
3118
3042
  multipleSelectRow(row) {
3119
3043
  this.grid.multipleSelectRow(row);
@@ -3132,7 +3056,7 @@ class Ng2SmartTableComponent {
3132
3056
  this.grid = new Grid(this.source, this.prepareSettings());
3133
3057
  }
3134
3058
  prepareSource() {
3135
- if (this.source instanceof DataSource) {
3059
+ if (this.source instanceof LocalDataSource) {
3136
3060
  return this.source;
3137
3061
  }
3138
3062
  return new LocalDataSource();
@@ -3143,7 +3067,7 @@ class Ng2SmartTableComponent {
3143
3067
  emitUserSelectRow(row) {
3144
3068
  this.multiRowSelect.emit({
3145
3069
  data: row ? row.getData() : null,
3146
- isSelected: row ? row.getIsSelected() : null,
3070
+ isSelected: row ? row.getIsSelected() : false,
3147
3071
  source: this.source,
3148
3072
  selected: this.grid.dataSet.getSelectedRowsData(),
3149
3073
  });
@@ -3229,117 +3153,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
3229
3153
  }]
3230
3154
  }] });
3231
3155
 
3232
- class ServerSourceConf {
3233
- constructor({ endPoint = '', sortFieldKey = '', sortDirKey = '', pagerPageKey = '', pagerLimitKey = '', filterFieldKey = '', totalKey = '', dataKey = '' } = {}) {
3234
- this.endPoint = endPoint ? endPoint : '';
3235
- this.sortFieldKey = sortFieldKey ? sortFieldKey : ServerSourceConf.SORT_FIELD_KEY;
3236
- this.sortDirKey = sortDirKey ? sortDirKey : ServerSourceConf.SORT_DIR_KEY;
3237
- this.pagerPageKey = pagerPageKey ? pagerPageKey : ServerSourceConf.PAGER_PAGE_KEY;
3238
- this.pagerLimitKey = pagerLimitKey ? pagerLimitKey : ServerSourceConf.PAGER_LIMIT_KEY;
3239
- this.filterFieldKey = filterFieldKey ? filterFieldKey : ServerSourceConf.FILTER_FIELD_KEY;
3240
- this.totalKey = totalKey ? totalKey : ServerSourceConf.TOTAL_KEY;
3241
- this.dataKey = dataKey ? dataKey : ServerSourceConf.DATA_KEY;
3242
- }
3243
- }
3244
- ServerSourceConf.SORT_FIELD_KEY = '_sort';
3245
- ServerSourceConf.SORT_DIR_KEY = '_order';
3246
- ServerSourceConf.PAGER_PAGE_KEY = '_page';
3247
- ServerSourceConf.PAGER_LIMIT_KEY = '_limit';
3248
- ServerSourceConf.FILTER_FIELD_KEY = '#field#_like';
3249
- ServerSourceConf.TOTAL_KEY = 'x-total-count';
3250
- ServerSourceConf.DATA_KEY = '';
3251
-
3252
- class ServerDataSource extends LocalDataSource {
3253
- constructor(http, conf = {}) {
3254
- super();
3255
- this.http = http;
3256
- this.lastRequestCount = 0;
3257
- this.conf = new ServerSourceConf(conf);
3258
- if (!this.conf.endPoint) {
3259
- throw new Error('At least endPoint must be specified as a configuration of the server data source.');
3260
- }
3261
- }
3262
- count() {
3263
- return this.lastRequestCount;
3264
- }
3265
- getElements() {
3266
- return this.requestElements()
3267
- .pipe(map(res => {
3268
- this.lastRequestCount = this.extractTotalFromResponse(res);
3269
- this.data = this.extractDataFromResponse(res);
3270
- return this.data;
3271
- })).toPromise();
3272
- }
3273
- /**
3274
- * Extracts array of data from server response
3275
- * @param res
3276
- * @returns {any}
3277
- */
3278
- extractDataFromResponse(res) {
3279
- const rawData = res.body;
3280
- const data = !!this.conf.dataKey ? getDeepFromObject(rawData, this.conf.dataKey, []) : rawData;
3281
- if (data instanceof Array) {
3282
- return data;
3283
- }
3284
- throw new Error(`Data must be an array.
3285
- Please check that data extracted from the server response by the key '${this.conf.dataKey}' exists and is array.`);
3286
- }
3287
- /**
3288
- * Extracts total rows count from the server response
3289
- * Looks for the count in the heders first, then in the response body
3290
- * @param res
3291
- * @returns {any}
3292
- */
3293
- extractTotalFromResponse(res) {
3294
- if (res.headers.has(this.conf.totalKey)) {
3295
- return +res.headers.get(this.conf.totalKey);
3296
- }
3297
- else {
3298
- const rawData = res.body;
3299
- return getDeepFromObject(rawData, this.conf.totalKey, 0);
3300
- }
3301
- }
3302
- requestElements() {
3303
- let httpParams = this.createRequesParams();
3304
- return this.http.get(this.conf.endPoint, { params: httpParams, observe: 'response' });
3305
- }
3306
- createRequesParams() {
3307
- let httpParams = new HttpParams();
3308
- httpParams = this.addSortRequestParams(httpParams);
3309
- httpParams = this.addFilterRequestParams(httpParams);
3310
- return this.addPagerRequestParams(httpParams);
3311
- }
3312
- addSortRequestParams(httpParams) {
3313
- if (this.sortConf) {
3314
- this.sortConf.forEach((fieldConf) => {
3315
- httpParams = httpParams.set(this.conf.sortFieldKey, fieldConf.field);
3316
- httpParams = httpParams.set(this.conf.sortDirKey, fieldConf.direction.toUpperCase());
3317
- });
3318
- }
3319
- return httpParams;
3320
- }
3321
- addFilterRequestParams(httpParams) {
3322
- if (this.filterConf.filters) {
3323
- this.filterConf.filters.forEach((fieldConf) => {
3324
- if (fieldConf['search']) {
3325
- httpParams = httpParams.set(this.conf.filterFieldKey.replace('#field#', fieldConf['field']), fieldConf['search']);
3326
- }
3327
- });
3328
- }
3329
- return httpParams;
3330
- }
3331
- addPagerRequestParams(httpParams) {
3332
- if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) {
3333
- httpParams = httpParams.set(this.conf.pagerPageKey, this.pagingConf['page']);
3334
- httpParams = httpParams.set(this.conf.pagerLimitKey, this.pagingConf['perPage']);
3335
- }
3336
- return httpParams;
3337
- }
3338
- }
3339
-
3340
3156
  /**
3341
3157
  * Generated bundle index. Do not edit.
3342
3158
  */
3343
3159
 
3344
- export { Cell, DefaultEditor, DefaultFilter, LocalDataSource, Ng2SmartTableComponent, Ng2SmartTableModule, ServerDataSource };
3160
+ export { Cell, DefaultEditor, DefaultFilter, LocalDataSource, Ng2SmartTableComponent, Ng2SmartTableModule };
3345
3161
  //# sourceMappingURL=den4ik92-ng2-smart-table.mjs.map