删除使用fnOpen在dataTable中动态创建的行

时间:2013-06-04 09:35:54

标签: jquery datatables

我通过创建dataTable(Parent)的新行,在dataTable(parent)中创建一个新的dataTable(child),使用fnOpen(indexOfRow,oTable,cssClass); 当我关闭这个表时,我只是在破坏dataTable(孩子),它正在摧毁!但在销毁dataTable(子)之后,我留下'indexOfRow'创建的行。 我想摆脱这个容纳孩子数据库的行!!

由于

/* snippet of the code */


$('#example tbody td:nth-child(n+2) ').on('click', function() {

    AnalyticalRole = rowValue(this);
    RotationPeriod = headerValue(this);

    var result=[],divAjax;
    nTr = $(this).parents('tr')[0]; /* indexOfRow: where i want to add need row, and this row will house my new datatable 
                                            This row has only one td with colspan=9
                                        */
     $.support.cors = true;
        $.ajax({
            url: REMOTE_CONTEXT_PATH+"detailsofcredits",
            dataType:"json",
            contentType:'application/json',
            crossDomain:true,
            data: {role:AnalyticalRole,rotationMonths:RotationPeriod},
            success: function (data) { 


                $.each(data,function(i,obj){                        
                    temp= {OrganizationName:obj.orgName,AnalystName:obj.analystName,CurrentRole:obj.currentRole,CurrentPrimary:obj.currentPrimary,RMRPrimary:obj.rmrPrimary,RMROther:obj.rmrOther,RMRChair:obj.rmrChair,CMR:obj.cmr}
                    result.push(temp);
                });

                if(result == 0 || result== null){
                    alert("No data found for the request");
                    table2Id.fnDestroy();
                    $("#div1").hide(); 

                    table2Id = 0;
                }
                else{
                    if(table2Id == 0){                        
                        divAjax = $("#div1").html(ajaxDataTableIntialisation(result));            
                    }
                    else{                    
                        table2Id.fnDestroy();
                        divAjax = $("#div1").html(ajaxDataTableIntialisation(result));            
                    }
                    table1Id.fnOpen(nTr, divAjax, 'dispaly'); /* opening new table at nTr*/
                    isTableTwoOpen=5;
                    $("#div1").show();
                }



            }
        })
        headerPrint(this);
        });

        $("body").on('click',"#closeTable2,#example>thead>tr>th", function()
        {
        table2Id.fnDestroy();
        /* I want to add sumthing here like.. fnDeleterow etc to delete the row created at nTr */
        $("#div1").hide(); 
        table2Id = 0;

        });
从上面的代码* /

调用

/ *函数

function ajaxDataTableIntialisation(data){
table2Id= $("#table2").dataTable(
        {
            "bRetrieve" : true,
            "bPaginate":true,
            "aaData": data,
            "aoColumns": [
                          { "mDataProp": "OrganizationName" },
                          { "mDataProp": "AnalystName" },
                          { "mDataProp": "CurrentRole" },
                          { "mDataProp": "CurrentPrimary" },
                          { "mDataProp": "RMRPrimary" },
                          { "mDataProp": "RMROther" },
                          { "mDataProp": "RMRChair" },
                          { "mDataProp": "CMR" },]    

        })

}

0 个答案:

没有答案