So I have a data being loaded to a table and user can click and add input to cells , what is and how do we check if there are changes to the table data ?
for example if user click cell and added an input it should return TRUE since there are changes if user just click the cell and did not make any changes on input or did not update any field then return FALSE.
I could pass the row data to edit() and then compare it to the existing dataSource if there are changes to any values.
So it will check if there are new changes with the row and compare it with the orignal data in the dataSource.
I wanted to detect any changes of dataSource
Thanks for any help and idea.
#blitz
https://stackblitz.com/edit/am-all-imports-65vtbu?file=app%2Fapp.component.html
#ts code
options: string[] = ['position', 'name', 'weight', 'symbol', 'symbol2'];
dataSource = ELEMENT_DATA;
edit(index: number, column: string) {
this.editableColumn = column;
this.editableIndex = index;
}
showInput(index: number, column: string) {
return this.editableColumn === column && this.editableIndex === index;
}
showValue(index: number, column: string) {
return this.editableColumn !== column || this.editableIndex !== index;
}
reset() {
this.editableColumn = '';
this.editableIndex = null;
}
}
#html code
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef>No.</th>
<td
mat-cell
*matCellDef="let element; let i = index"
(click)="edit(i, 'position')"
>
<span *ngIf="showValue(i, 'position'); else editPlace">{{
element.position
}}</span>
<ng-template #editPlace>
<mat-form-field>
<input
matInput
placeholder="Placeholder"
(blur)="reset()"
appFocusOnLoad
[(ngModel)]="element.position"
/>
</mat-form-field>
</ng-template>
</td>
</ng-container>
JSON.stringify(a) === JSON.stringify(b). Does this answer your question?dataSourcethat you are using?