I have a requirement to display some data using a mat table. One of the columns will contain a slide toggle through which I can change a property (let's call it 'active').
I'm also using NgRx to store/modify the data.
So, the state is global and saved in the NgRx store. My solution is to get the data using a selector and define an action for changing the 'active' property. The action will be handled by a reducer.
After the data is changed, the selector will return a new value and the table will reflect that.
This is the main component:
ngOnInit() {
this.dataSource = this.store.pipe(select(selectPeriodicElements));
}
updateActiveStatus(element: PeriodicElement) {
this.store.dispatch(toggleActiveStatus({id: element.id}));
}
Here is the complete example
My issue is that the solution doesn't seem to be efficient. If I use the developer tools to inspect the DOM and I update one row, then every row seems to be redrawn, not just the one which was updated. Also, the animation for the slide toggle is missing (because the entire table is being redrawn I guess).
I searched for a better alternative, but I wasn't able to find one, even though this should be a popular requirement.
So, my question is how to update a row from a mat table when NgRx is being used?
Thank you!