Deleting row on ajax return
Deleting row on ajax return

i have a table which i fetch from my database. After fetching, i put it in a html table format and then initialize datatable on it.
So the database and datatable are not linked.
row | user | salary | bonus | toggle | |
---|---|---|---|---|---|
1 | 2 | 20 | yes | button | |
2 | 6 | 50 | no | button | |
3 | 8 | 80 | yes | button |
Column salary and user have dropdown filter in header.
Now i have a button in every row of the datatable clicking which toggles the value of bonus in the DATABASE.
So lets say i click on button in row 3, then an ajax call will be made to update the bonus value of this row to 'NO' in DATABASE.
what i want is that if the ajax call is successful then i select row 3 again from database and update row 3 in the datatable.
How do i do this in ajax call? How do i know which row to update?
My data has more than 10000 entries. i dont want that if any filter has been applied using header filters, they get reset. Also i dont want the datatable gets reset to page 1 upon update. If after update that particular row adheres to the header filter then it will be shown or it will be filtered out.
Replies
This example shows how to create row buttons and get the selected row when clicked:
http://live.datatables.net/xijecupo/1/edit
Within the click event make your Ajax request and have the server return the updated row data. In the Ajax
success
function get the updated row data and userow().data()
to update the data for that row orrow().remove()
to remove the row. Something like what the Editor does:https://editor.datatables.net/manual/server#Example-data-exchanges
Kevin