Skip to content Skip to sidebar Skip to footer

How Can I Delete The Row From Datatable In Ui,though I Could Successfully Delete From Server Using Ajax Call

I have a data table and in each row I have a button Delete. ON click of Delete i am making an ajax call and deleting the row from server by passing the id. But on success of ajax c

Solution 1:

The reason is that this within AJAX success callback refers to XHR object, so you may assign const tr = table.row($(this).closest('tr')) outside of success callback and then do tr.remove().draw() upon successful deletion server-side.

p.s. also, note that I have used closest('tr') rather than parents('tr') as it is less error prone, since the latter may return array if your button happen to have multiple <tr> parents

Solution 2:

Add this line on success call back of ajax

table.row( $(this).parents('tr') ).remove().draw();

Post a Comment for "How Can I Delete The Row From Datatable In Ui,though I Could Successfully Delete From Server Using Ajax Call"