删除行后,Jquery Datatable处理消息不会消失

时间:2011-07-21 20:17:22

标签: jquery-plugins datatables row

这是代码......

var oTable;
var aData;
var row;

$(document).ready(function() {

                    $('#example tbody tr').live('click', function (event) { 

                        $(oTable.fnSettings().aoData).each(function (){
                        $(this.nTr).removeClass('row_selected');
                    });

            $(event.target.parentNode).addClass('row_selected');    
            aData = oTable.fnGetData(this); // get datarow
            row = $(this).closest("tr").get(0);
        });

            /* Add a click handler for the delete row */
                $('#delete').click( function() {
                    $.ajax({
                    type: "GET",
                    url: "<?php echo base_url(); ?>Test/DeleteData",
                    data: "id="+aData[0],
                    success: function(msg){
                    //oTable.fnDeleteRow(aData);
                    var anSelected = fnGetSelected( oTable );
                    oTable.fnDeleteRow( anSelected[0] );
                    oTable.fnDeleteRow(oTable.fnGetPosition(row));
                }
            });      
                } );

            /* Init the table */
                oTable = $('#example').dataTable( {
                "bProcessing": true,
                "bServerSide": true,
                "sAjaxSource": "<?php echo base_url(); ?>Test/Listener",
                "sPaginationType": "full_numbers",
                "iDisplayLength": 1,
                "bSortClasses": false,
                "aoColumns": [ { "bVisible": false} , null, null ]
                } );    


            } );    
            /* Get the rows which are currently selected */
            function fnGetSelected( oTableLocal )
            {
                var aReturn = new Array();
                var aTrs = oTableLocal.fnGetNodes();

                for ( var i=0 ; i<aTrs.length ; i++ )
                {
                    if ( $(aTrs[i]).hasClass('row_selected') )
                    {
                        aReturn.push( aTrs[i] );
                    }
                }
                return aReturn;
            }
What is happening :-
The server side data gets deleted on clicking delete link.But the Datatable doesnt refresh after deleting a row on server.The usual "processing" message comes after deletion on server.It stays there.The UI row stays there highlighted with message "Processing" in the middle of the page

What i have observed is :-
1)The response of Ajax source after the delete url is called is this :-
{"sEcho":1,"iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":[["11","PD101-DH1234","adsasd"]],"sColumns":"PartId,PartNumber,PartDescription"}
2)After using firebug,i observed no abnormalities.Both the delete and get source requests are executed perfectly with response OK.
3)I am using FireFox 4.1
4)I am using DataTables 1.8.1 build.

现在问题: -

我在上面的代码中做了哪些更改,以便删除数据表UI行并刷新数据表以带来剩余的行??? 请帮帮我。我是数据表的新手。这个问题不会消失。我已经尝试了一切!等待回复:)

1 个答案:

答案 0 :(得分:0)

您是否尝试在删除行后调用fnDraw()?

oTable.fnDraw();