0

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 ?

shilovk
  • 11,718
  • 17
  • 75
  • 74
chloe
  • 33
  • 5

1 Answers1

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.

  1. In your component file create an array to hold your edited rows... selectedRows: any[] = [];
  2. 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.
  3. 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