3

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>
4

3 回答 3

2

您可以使用 fnDeleteRow 删除数据表中的一行。这个函数会自动重绘表格。

参考这个,http://datatables.net/api

于 2013-08-29T05:01:23.513 回答
2

它将缓存初始化中的所有信息,当您尝试执行某些操作(即排序)时,它将使用现有数据集重新绘制表格。因此,您应该使用draw(false)来防止重新绘制。

 table.row('.selectedRow').remove().draw( false );
于 2015-12-10T20:07:42.990 回答
1

您可以使用以下代码:

var rowid = document.getElementById(id);
var Pos = dt.fnGetPosition(rowid);
dt.fnDeleteRow(Pos);

这里 id 是您要删除的唯一行 ID。

于 2014-09-09T11:21:03.507 回答