when data has changed we can update the table by dataSource = new MatTableDataSource<PeriodicElement>([])
and then assign data to the datasource (this.datasource = data)
will automatically update the table.
We also can use this.changeDetectorRefs.detectChanges()
alternatively.
which one is better to be used?
I think it will work like what I mentioned below, but I doubt: assume we use these two methods:
method 1) new MatTableDataSource
method 2) changeDetectorRefs
So
init data:
data=[
{id=1, price = 8, buy = 2},
{id=2, price = 10, buy = 5},
]
and new data:
data=[
{id=1, price = 8, buy = 2},
{id=2, price = 20, buy = 5}, // price has changed (update)
]
Then:
If we use method 1: the whole rows in the mat table will be affected.
if we use method 2: just the second row with id 2 will be changed and the first row in the table will not change.
Is it right? I want to know which one is more good to use? (if it's like what I explained then method 2 will be preferred)