Redirect after adding a row?
Redirect after adding a row?

After adding a row to the table with row.add(), what is a good way to trigger redirecting to another page?
I don’t think createdRow is what I need, as that is for all rows, not just the added one.
Similar question here:
https://datatables.net/forums/discussion/30233/redirect-to-a-new-page-after-insert-a-new-row-passing-values
I see it may be possible with MutationObserver, but I’d like to see if there is a better way.
Thanks for any guideance!
This question has an accepted answers - jump to answer
Answers
Unless I'm missing something Datatables does not need to be involved in this. After you use
row.add()
then using something like window.location.replace to redirect to the desired page.Kevin
Yes but what can I use to trigger that? The row is added via save function, not my function.
There are a list of Datatables events here. The
draw
event would be an option as thedraw()
API is typically used withrow.add()
. Howeverdraw
triggers for other events like sorting and searching. So there would need to be a way to determine if a new row was added.How is this Save function used? Is it a Datatables Editor function? Maybe there is a trigger from it that can be used.
Do you need to get the data of the new row?
I've never used a
MutationObserver
but in looking at the docs it triggers when there is a DOM event. Usingrow.add()
might not change the DOM if the new row is not displayed on the page. But I can't ay for sure.Kevin
Oh thanks much!! I’m sure I can make one of those work. I missed the events page in all my searches...
https://datatables.net/reference/event/
https://editor.datatables.net/reference/event/
Will share solution once complete.
I ended up using the editor
postCreate
event.Not sure if above is the best way to access the ID data, but it works!