I'm using the primeng datatable which have columns are editable. I want to mark the cell as dirty once it's been edited and save the edited rows to the database. Can anyone advise is there a way to do this ?
Asked
Active
Viewed 485 times
1 Answers
0
It really depends on how you are trying to handle the saves. The default way (save as soon as focus of the input has changed) or save a bunch of changes based on user action (i.e. the user clicks save and saves them all at once). I am assuming the second option since that seems to make the most sense based on your question.
This is how I've accomplished this in a project I'm currently working on.
- In your component file create an array to hold your edited rows...
selectedRows: any[] = [];
- Use the
(onRowSelect)="yourRowSelectHandler($event)"
event handler. a. The event will include a data property that has all the data from the selected row. b. Push the data to your selectedRows array. - When the user clicks the save button you can loop through the selectedRows array and save the data.
Here is a plunkr to demonstrate the basics: http://plnkr.co/edit/59AghKq6NtOXvndT64Iy?p=preview

user7087663
- 1
- 1
- 1