mat-table-ext 0.0.7 → 0.0.9

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 (89) hide show
  1. package/.editorconfig +16 -0
  2. package/.vscode/extensions.json +4 -0
  3. package/.vscode/launch.json +20 -0
  4. package/.vscode/tasks.json +42 -0
  5. package/LICENSE +21 -0
  6. package/angular.json +150 -0
  7. package/package.json +46 -58
  8. package/projects/mat-table-ext/.browserslistrc +16 -0
  9. package/projects/mat-table-ext/README.md +57 -0
  10. package/projects/mat-table-ext/karma.conf.js +44 -0
  11. package/projects/mat-table-ext/ng-package.json +9 -0
  12. package/projects/mat-table-ext/package.json +38 -0
  13. package/projects/mat-table-ext/src/lib/components/column-pinning/column-pinning.component.html +7 -0
  14. package/projects/mat-table-ext/src/lib/components/column-pinning/column-pinning.component.scss +9 -0
  15. package/projects/mat-table-ext/src/lib/components/column-pinning/column-pinning.component.spec.ts +23 -0
  16. package/projects/mat-table-ext/src/lib/components/column-pinning/column-pinning.component.ts +48 -0
  17. package/projects/mat-table-ext/src/lib/components/editing/editing.component.html +55 -0
  18. package/projects/mat-table-ext/src/lib/components/editing/editing.component.scss +19 -0
  19. package/projects/mat-table-ext/src/lib/components/editing/editing.component.spec.ts +23 -0
  20. package/projects/mat-table-ext/src/lib/components/editing/editing.component.ts +110 -0
  21. package/projects/mat-table-ext/src/lib/components/filter-columns-component/filter-columns-component.component.html +26 -0
  22. package/projects/mat-table-ext/src/lib/components/filter-columns-component/filter-columns-component.component.scss +0 -0
  23. package/projects/mat-table-ext/src/lib/components/filter-columns-component/filter-columns-component.component.spec.ts +23 -0
  24. package/projects/mat-table-ext/src/lib/components/filter-columns-component/filter-columns-component.component.ts +54 -0
  25. package/projects/mat-table-ext/src/lib/directives/resize-column.directive.ts +103 -0
  26. package/projects/mat-table-ext/src/lib/mat-table-ext.component.html +285 -0
  27. package/projects/mat-table-ext/src/lib/mat-table-ext.component.spec.ts +25 -0
  28. package/projects/mat-table-ext/src/lib/mat-table-ext.component.ts +985 -0
  29. package/projects/mat-table-ext/src/lib/mat-table-ext.module.ts +127 -0
  30. package/projects/mat-table-ext/src/lib/mat-table-ext.scss +181 -0
  31. package/projects/mat-table-ext/src/lib/mat-table-ext.service.spec.ts +16 -0
  32. package/projects/mat-table-ext/src/lib/mat-table-ext.service.ts +12 -0
  33. package/projects/mat-table-ext/src/lib/models/tableExtModels.ts +85 -0
  34. package/{public-api.d.ts → projects/mat-table-ext/src/public-api.ts} +5 -1
  35. package/projects/mat-table-ext/src/test.ts +27 -0
  36. package/projects/mat-table-ext/tsconfig.lib.json +15 -0
  37. package/projects/mat-table-ext/tsconfig.lib.prod.json +10 -0
  38. package/projects/mat-table-ext/tsconfig.spec.json +17 -0
  39. package/projects/mat-table-ext-example/.browserslistrc +16 -0
  40. package/projects/mat-table-ext-example/karma.conf.js +44 -0
  41. package/projects/mat-table-ext-example/src/app/app.component.html +576 -0
  42. package/projects/mat-table-ext-example/src/app/app.component.scss +0 -0
  43. package/projects/mat-table-ext-example/src/app/app.component.spec.ts +31 -0
  44. package/projects/mat-table-ext-example/src/app/app.component.ts +173 -0
  45. package/projects/mat-table-ext-example/src/app/app.module.ts +40 -0
  46. package/projects/mat-table-ext-example/src/app/service/custom-table.service.spec.ts +16 -0
  47. package/projects/mat-table-ext-example/src/app/service/custom-table.service.ts +18 -0
  48. package/projects/mat-table-ext-example/src/assets/.gitkeep +0 -0
  49. package/projects/mat-table-ext-example/src/assets/data.json +100003 -0
  50. package/projects/mat-table-ext-example/src/environments/environment.prod.ts +3 -0
  51. package/projects/mat-table-ext-example/src/environments/environment.ts +16 -0
  52. package/projects/mat-table-ext-example/src/favicon.ico +0 -0
  53. package/projects/mat-table-ext-example/src/index.html +14 -0
  54. package/projects/mat-table-ext-example/src/main.ts +12 -0
  55. package/projects/mat-table-ext-example/src/polyfills.ts +53 -0
  56. package/projects/mat-table-ext-example/src/styles.scss +23 -0
  57. package/projects/mat-table-ext-example/src/test.ts +26 -0
  58. package/projects/mat-table-ext-example/tsconfig.app.json +15 -0
  59. package/projects/mat-table-ext-example/tsconfig.spec.json +18 -0
  60. package/tsconfig.json +38 -0
  61. package/esm2020/lib/components/column-pinning/column-pinning.component.mjs +0 -58
  62. package/esm2020/lib/components/editing/editing.component.mjs +0 -122
  63. package/esm2020/lib/components/filter-columns-component/filter-columns-component.component.mjs +0 -68
  64. package/esm2020/lib/directives/resize-column.directive.mjs +0 -99
  65. package/esm2020/lib/mat-table-ext.component.mjs +0 -1021
  66. package/esm2020/lib/mat-table-ext.module.mjs +0 -237
  67. package/esm2020/lib/mat-table-ext.service.mjs +0 -20
  68. package/esm2020/lib/models/tableExtModels.mjs +0 -2
  69. package/esm2020/mat-table-ext.mjs +0 -5
  70. package/esm2020/public-api.mjs +0 -11
  71. package/fesm2015/mat-table-ext.mjs +0 -1585
  72. package/fesm2015/mat-table-ext.mjs.map +0 -1
  73. package/fesm2020/mat-table-ext.mjs +0 -1582
  74. package/fesm2020/mat-table-ext.mjs.map +0 -1
  75. package/index.d.ts +0 -5
  76. package/lib/components/column-pinning/column-pinning.component.d.ts +0 -27
  77. package/lib/components/editing/editing.component.d.ts +0 -42
  78. package/lib/components/filter-columns-component/filter-columns-component.component.d.ts +0 -26
  79. package/lib/directives/resize-column.directive.d.ts +0 -27
  80. package/lib/mat-table-ext.component.d.ts +0 -348
  81. package/lib/mat-table-ext.module.d.ts +0 -58
  82. package/lib/mat-table-ext.service.d.ts +0 -11
  83. package/lib/models/tableExtModels.d.ts +0 -76
  84. /package/{assets → projects/mat-table-ext/assets}/_theming.scss +0 -0
  85. /package/{assets → projects/mat-table-ext/assets}/pinIcon.svg +0 -0
  86. /package/{assets → projects/mat-table-ext/assets}/pinLeft.svg +0 -0
  87. /package/{assets → projects/mat-table-ext/assets}/pinNone.svg +0 -0
  88. /package/{assets → projects/mat-table-ext/assets}/pinRight.svg +0 -0
  89. /package/{assets → projects/mat-table-ext/assets}/pinned.svg +0 -0
@@ -0,0 +1,55 @@
1
+ <div *ngIf="!templateRef" style="height: 100%;" class="main-dialog-container">
2
+ <div mat-dialog-title class="dialog-title-container">
3
+ <h2 style="margin: 0;">Edit Row</h2>
4
+ <span class="example-spacer"></span>
5
+ <button mat-icon-button aria-label="Example icon button with a vertical three dot icon">
6
+ <mat-icon mat-dialog-close style="cursor: pointer;" fxFlex="5">close</mat-icon>
7
+ </button>
8
+ </div>
9
+ <mat-dialog-content style="margin-right: 20px;">
10
+ <div style="display: flex; flex-direction: column;">
11
+ <ng-container *ngFor="let key of keys">
12
+ <!-- Number Type -->
13
+ <mat-form-field *ngIf="types[key] == 'number'" appearance="outline" class="inline-editing-field">
14
+ <mat-label>{{key | titlecase}}</mat-label>
15
+ <input matInput type="number" [(ngModel)]="dialogData['row'][key]" [ngModelOptions]="{standalone: true}">
16
+ </mat-form-field>
17
+
18
+ <!-- String Type -->
19
+
20
+ <mat-form-field *ngIf="types[key] == 'string'" appearance="outline" class="inline-editing-field">
21
+ <mat-label>{{key | titlecase}}</mat-label>
22
+ <input matInput type="text" [(ngModel)]="dialogData['row'][key]" [ngModelOptions]="{standalone: true}">
23
+ </mat-form-field>
24
+ <mat-form-field *ngIf="types[key] == 'date'" appearance="outline" class="inline-editing-field">
25
+ <mat-label>{{key | titlecase}}</mat-label>
26
+ <input matInput type="text" [(ngModel)]="dialogData['row'][key]" [ngModelOptions]="{standalone: true}">
27
+ </mat-form-field>
28
+ <!-- Selection Type -->
29
+
30
+ <mat-form-field *ngIf="types[key] == 'selection'" appearance="outline" class="inline-editing-field">
31
+ <mat-label>{{key | titlecase}}</mat-label>
32
+ <mat-select [value]="dialogData['row'][key].value" [(ngModel)]="dialogData['row'][key].value">
33
+ <mat-option *ngFor="let option of dialogData['row'][key].options" [value]="option">
34
+ {{option}}
35
+ </mat-option>
36
+ </mat-select>
37
+ </mat-form-field>
38
+ <!-- Boolean Type -->
39
+ <p>
40
+ <mat-checkbox *ngIf="types[key] == 'boolean'" color="primary" [(ngModel)]="dialogData['row'][key]">
41
+ <mat-label>{{key | titlecase}}</mat-label>
42
+ </mat-checkbox>
43
+ </p>
44
+ </ng-container>
45
+ </div>
46
+ </mat-dialog-content>
47
+ <div class="spacer"></div>
48
+ <mat-dialog-actions style="margin-top: 20px;" align="end">
49
+ <button mat-raised-button color="warn" mat-dialog-close>
50
+ Cancel
51
+ </button>
52
+ <button mat-raised-button color="primary" (click)="closeDialog()">Save</button>
53
+ </mat-dialog-actions>
54
+ </div>
55
+ <ng-container *ngIf="templateRef" [ngTemplateOutlet]="templateRef" [ngTemplateOutletContext]="{data:{row:templateRow,columns:columns,columnKeys:templateKeys,columnTypes:templateTypes,closeDialog:closeTemplateDialog}}"></ng-container>
@@ -0,0 +1,19 @@
1
+ .main-dialog-container {
2
+ display: flex;
3
+ flex-direction: column;
4
+ }
5
+
6
+ .main-dialog-container mat-dialog-content {
7
+ overflow-y: auto;
8
+ margin: 0px;
9
+ padding: 0 0 0 20px;
10
+ }
11
+
12
+ .dialog-title-container {
13
+ display: flex;
14
+ align-items: center;
15
+ }
16
+
17
+ .spacer {
18
+ flex-grow: 1;
19
+ }
@@ -0,0 +1,23 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { PopupModalComponent } from './editing.component';
4
+
5
+ describe('PopupModalComponent', () => {
6
+ let component: PopupModalComponent;
7
+ let fixture: ComponentFixture<PopupModalComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ PopupModalComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(PopupModalComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
@@ -0,0 +1,110 @@
1
+ import { Component, Inject, OnInit, TemplateRef } from '@angular/core';
2
+ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
3
+ import { MTExColumn } from '../../models/tableExtModels';
4
+ import { MatTableExtService } from '../../mat-table-ext.service';
5
+
6
+ @Component({
7
+ selector: 'app-editing',
8
+ templateUrl: './editing.component.html',
9
+ styleUrls: ['./editing.component.scss'],
10
+ })
11
+ export class EditingComponent implements OnInit {
12
+ public templateRef!: TemplateRef<any>;
13
+ public keys: string[] = [];
14
+ public templateKeys: string[] = [];
15
+ public types: any = {};
16
+ public templateTypes: any = {};
17
+ public columns: MTExColumn[] = [];
18
+ public templateRow: any = {};
19
+
20
+ constructor(
21
+ public dialogRef: MatDialogRef<EditingComponent>,
22
+ @Inject(MAT_DIALOG_DATA) public dialogData: any,
23
+ public service: MatTableExtService
24
+ ) { }
25
+
26
+ ngOnInit(): void {
27
+ this.setData(this.dialogData);
28
+ }
29
+ /**
30
+ * @description This method is used to set data for editing.
31
+ * @param value dialog Data
32
+ */
33
+ setData(value: any) {
34
+ let row = value.row;
35
+ let types: any = {};
36
+ this.keys = [];
37
+ this.columns = value.columns;
38
+ this.columns.forEach((column) => {
39
+ this.keys.push(column.field);
40
+ if (column.type == 'selection') {
41
+ types[column.field] = column.type;
42
+ let temp = row[column.field];
43
+ row[column.field] = {
44
+ value: temp,
45
+ options: column.options,
46
+ };
47
+ } else {
48
+ types[column.field] = column.type;
49
+ }
50
+ });
51
+ this.types = types;
52
+ this.setTemplateRef(value);
53
+ }
54
+ /**
55
+ * @description This method is used to set the data when data comes in from cus template.
56
+ * @param value template value
57
+ */
58
+ setTemplateRef(value: any) {
59
+ if (value.templateRef !== undefined) {
60
+ this.templateRow = { ...value.row };
61
+ let types: any = {};
62
+ this.templateKeys = [];
63
+ this.columns.forEach((column) => {
64
+ this.templateKeys.push(column.field);
65
+ if (column.type == 'selection') {
66
+ types[column.field] = column.type;
67
+ let temp = this.templateRow[column.field];
68
+ this.templateRow[column.field] = {
69
+ value: temp,
70
+ options: column.options,
71
+ };
72
+ } else {
73
+ types[column.field] = column.type;
74
+ }
75
+ });
76
+ this.templateTypes = types;
77
+ this.templateRef = value.templateRef;
78
+ }
79
+ }
80
+ /**
81
+ * @description This method is triggered when dialog is closed and also emits the dialog closed event data.
82
+ */
83
+ closeDialog() {
84
+ let rowData = { ...this.dialogData.row };
85
+ this.keys.forEach((key: any) => {
86
+ if (this.types[key] === 'selection') {
87
+ let temp = rowData[key].value;
88
+ rowData[key] = temp;
89
+ }
90
+ });
91
+ this.dialogRef.close(rowData);
92
+ }
93
+
94
+ /**
95
+ * @description This method is called when the dialog is closed custom template action.
96
+ * @param row row to be edited.
97
+ * @param keys keys of columns
98
+ * @param types column types
99
+ */
100
+ closeTemplateDialog(row: any, keys: string[], types: string[]) {
101
+ let rowData = { ...row };
102
+ keys.forEach((key: any) => {
103
+ if (types[key] === 'selection') {
104
+ let temp = rowData[key].value;
105
+ rowData[key] = temp;
106
+ }
107
+ });
108
+ this.dialogRef.close(rowData);
109
+ }
110
+ }
@@ -0,0 +1,26 @@
1
+
2
+ <ng-container *ngIf="obj">
3
+ <!-- Number Type -->
4
+ <mat-form-field *ngIf="obj.type == 'number'" appearance="outline" class="inline-editing-field" >
5
+ <input matInput type="number" [formControl]="numberCtrl">
6
+ </mat-form-field>
7
+
8
+ <!-- String Type -->
9
+ <mat-form-field *ngIf="obj.type == 'string'" appearance="outline" class="inline-editing-field">
10
+ <input matInput type="text" [formControl]="stringCtrl">
11
+ </mat-form-field>
12
+ <mat-form-field *ngIf="obj.type == 'date'" appearance="outline" class="inline-editing-field">
13
+ <input matInput type="date" [formControl]="dateCtrl">
14
+ </mat-form-field>
15
+ <!-- Selection Type -->
16
+ <mat-form-field *ngIf="obj.type == 'selection'" appearance="outline" class="inline-editing-field">
17
+ <mat-select [value]="" [formControl]="selectionCtrl">
18
+ <mat-option *ngFor="let option of obj.options" [value]="option">
19
+ {{option}}
20
+ </mat-option>
21
+ </mat-select>
22
+ </mat-form-field>
23
+ <!-- Boolean Type -->
24
+ <mat-checkbox (click)="$event.stopPropagation()" *ngIf="obj.type == 'boolean'" color="primary" [formControl]="booleanCtrl"></mat-checkbox>
25
+
26
+ </ng-container>
@@ -0,0 +1,23 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { FilterColumnsComponentComponent } from './filter-columns-component.component';
4
+
5
+ describe('FilterColumnsComponentComponent', () => {
6
+ let component: FilterColumnsComponentComponent;
7
+ let fixture: ComponentFixture<FilterColumnsComponentComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ declarations: [ FilterColumnsComponentComponent ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(FilterColumnsComponentComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
@@ -0,0 +1,54 @@
1
+ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2
+ import { FormControl } from '@angular/forms';
3
+
4
+ @Component({
5
+ selector: 'app-filter-columns-component',
6
+ templateUrl: './filter-columns-component.component.html',
7
+ styleUrls: ['./filter-columns-component.component.scss'],
8
+ })
9
+ export class FilterColumnsComponentComponent implements OnInit {
10
+ @Input() obj!: any;
11
+ @Output() filterOutput: EventEmitter<any> = new EventEmitter<any>();
12
+ stringCtrl: FormControl = new FormControl();
13
+ numberCtrl: FormControl = new FormControl();
14
+ dateCtrl: FormControl = new FormControl();
15
+ booleanCtrl: FormControl = new FormControl();
16
+ selectionCtrl: FormControl = new FormControl();
17
+ constructor() {}
18
+ ngOnInit(): void {
19
+ this.stringCtrl.valueChanges.subscribe((value) => {
20
+ this.checkValue(value);
21
+ });
22
+ this.dateCtrl.valueChanges.subscribe((value) => {
23
+ this.checkValue(value);
24
+ });
25
+ this.numberCtrl.valueChanges.subscribe((value) => {
26
+ this.checkValue(value);
27
+ });
28
+ this.booleanCtrl.valueChanges.subscribe((value) => {
29
+ this.checkValue(value);
30
+ });
31
+ this.selectionCtrl.valueChanges.subscribe((value) => {
32
+ this.checkValue(value);
33
+ });
34
+ }
35
+ /**
36
+ * @description This method is make value is valid and not null.
37
+ * @param value value to check its type.
38
+ */
39
+ checkValue(value: any) {
40
+ if (value || value == '') {
41
+ this.emitOutput(value);
42
+ } else if (value == null) {
43
+ this.emitOutput('');
44
+ }
45
+ }
46
+ /**
47
+ * @description This method will emit seach value to parent component.
48
+ * @param value value on which base table rows are filtered.
49
+ */
50
+ emitOutput(value: any) {
51
+ let obj = { [this.obj.field]: value };
52
+ this.filterOutput.emit(obj);
53
+ }
54
+ }
@@ -0,0 +1,103 @@
1
+ import { Directive, OnInit, Renderer2, Input, ElementRef, OnChanges } from "@angular/core";
2
+
3
+ @Directive({
4
+ selector: "[columnsResizable]"
5
+ })
6
+ export class ResizeColumnDirective implements OnInit, OnChanges {
7
+ columnsResizable$: boolean = false;
8
+ @Input() set columnsResizable(val: boolean) {
9
+ this.columnsResizable$ = val;
10
+ }
11
+ get columnsResizable() {
12
+ return this.columnsResizable$;
13
+ }
14
+ @Input() index!: number;
15
+ private startX!: number;
16
+ private startWidth!: number;
17
+ private column: HTMLElement;
18
+ private table!: HTMLElement;
19
+ private pressed!: boolean;
20
+
21
+ constructor(private renderer: Renderer2, private el: ElementRef) {
22
+ this.column = this.el.nativeElement;
23
+ }
24
+
25
+ ngOnInit() {
26
+ if (this.columnsResizable$) {
27
+ const row = this.renderer.parentNode(this.column);
28
+ const thead = this.renderer.parentNode(row);
29
+ this.table = this.renderer.parentNode(thead);
30
+
31
+ const resizer = this.renderer.createElement("span");
32
+ this.renderer.addClass(resizer, "resize-holder");
33
+ this.renderer.setAttribute(resizer, 'id', "resizeHolderSpan");
34
+ this.renderer.appendChild(this.column, resizer);
35
+ this.renderer.listen(resizer, "mousedown", this.onMouseDown);
36
+ this.renderer.listen(this.table, "mousemove", this.onMouseMove);
37
+ this.renderer.listen("document", "mouseup", this.onMouseUp);
38
+ }
39
+ else {
40
+ this.removeDragElementFromDom();
41
+ }
42
+ }
43
+ ngOnChanges() {
44
+ if (this.columnsResizable$) {
45
+ const row = this.renderer.parentNode(this.column);
46
+ const thead = this.renderer.parentNode(row);
47
+ const resizer = this.renderer.createElement("span");
48
+ this.table = this.renderer.parentNode(thead);
49
+ this.renderer.addClass(resizer, "resize-holder");
50
+ this.renderer.setAttribute(resizer, 'id', "resizeHolderSpan");
51
+ this.renderer.appendChild(this.column, resizer);
52
+ this.renderer.listen(resizer, "mousedown", this.onMouseDown);
53
+ this.renderer.listen(this.table, "mousemove", this.onMouseMove);
54
+ this.renderer.listen("document", "mouseup", this.onMouseUp);
55
+ }
56
+ else {
57
+ this.removeDragElementFromDom();
58
+ }
59
+ }
60
+
61
+ onMouseDown = (event: MouseEvent) => {
62
+ this.pressed = true;
63
+ this.startX = event.pageX;
64
+ this.startWidth = this.column.offsetWidth;
65
+ };
66
+
67
+ onMouseMove = (event: MouseEvent) => {
68
+ const offset = 5;
69
+ if (this.pressed && event.buttons) {
70
+ this.renderer.addClass(this.table, "resizing");
71
+ // Calculate width of column
72
+ let width =
73
+ this.startWidth + (event.pageX - this.startX - offset);
74
+ const tableCells = Array.from(this.table.querySelectorAll(".mat-row")).map(
75
+ (row: any) => row.querySelectorAll(".mat-cell").item(this.index)
76
+ );
77
+ // Set table header width
78
+ this.renderer.setStyle(this.column, "width", `${width}px`);
79
+ // Set table cells width
80
+ for (const cell of tableCells) {
81
+ if (cell && cell !== null)
82
+ this.renderer.setStyle(cell, "width", `${width}px`);
83
+ }
84
+ }
85
+ };
86
+
87
+ onMouseUp = (event: MouseEvent) => {
88
+ if (this.pressed) {
89
+ this.pressed = false;
90
+ this.renderer.removeClass(this.table, "resizing");
91
+ }
92
+ };
93
+ /**
94
+ * @description This method is used remove resizing handlers from the table headers when column resizing is disabled.
95
+ */
96
+ removeDragElementFromDom() {
97
+ let ele = document.getElementById('resizeHolderSpan')
98
+ if (ele && ele !== null && ele !== undefined) {
99
+ this.renderer.removeChild(this.column, ele);
100
+ }
101
+ }
102
+ }
103
+