Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh DataTable after a remove() done

I've done a row remove() and then I tried to fnDestroy() and initialize back the DataTable. The record count and the pagination does not effected(The *DataTable not refreshed)*.

I've also tried to use fnDraw() but it's still no use.

I've looked at the page source and the deleted row html is still there.

I'm using Ajax to delete the row. Appreciate your help

This is my delete script:

$(document).ready(function()
        {
            $('table#sample_1 td a.delete').click(function()
            {
                if (confirm("Are you sure you want to delete this row?"))
                {
                    var id = $(this).parent().parent().attr('id');
                    var data = 'id=' + id ;
                    var parent = $(this).parent().parent();

                    $.ajax(
                    {
                           type: "POST",
                           url: "process.php",
                           dataType: "json",
                           data: data,
                           cache: false,

                           success: function()
                           {

                            var dtable = $('#sample_1').dataTable();
                        dtable.fnDestroy();


                        parent.fadeOut('slow', function() {$(this).remove();});


                        //Reinitialize the datatable
                        $('#sample_1').dataTable({
                                    "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
                                    "sPaginationType": "bootstrap",
                                    "oLanguage": {
                                        "sLengthMenu": "_MENU_ records per page",
                                        "oPaginate": {
                                            "sPrevious": "Prev",
                                            "sNext": "Next"
                                        }
                                    },
                                    "aoColumnDefs": [{
                                        'bSortable': false,
                                        'aTargets': [0]
                                    }]
                        });

                           }
                     });
                }
            });


        });


        </script>
like image 435
Redzwan Latif Avatar asked Aug 10 '26 07:08

Redzwan Latif


1 Answers

You can use fnDeleteRow to delete a row in the datatable. This function will automatically redraw the table.

Refer this, http://datatables.net/api

like image 155
Manu M Avatar answered Aug 13 '26 05:08

Manu M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!