How to reinitialize jquery Datatable

前端 未结 2 1326
暗喜
暗喜 2021-02-20 11:26

How to reinitialize a jQuery datatable? I even tried to remove table element. Still that table is displaying. My code is like this:

function removeExistingDat         


        
相关标签:
2条回答
  • 2021-02-20 11:49

    You may use fnReloadAjax

    http://datatables.net/forums/discussion/256/fnreloadajax/p1

    oTable = $('#FTable').dataTable( {
         "bDestroy":true,
         "bJQueryUI": true,
        "sScrollX": "100%",
        "sScrollXInner": tablewidth+"px",
        "bScrollCollapse": true,
        "bSort":false,
        "iDisplayLength" : 50,
        "sPaginationType" : "full_numbers",
        "aLengthMenu": [[10, 18, 50, -1], [10, 18, 50, "All"]]
    } );
    
    function reinit(){
        oTable.fnReloadAjax( 'media/examples_support/json_source2.txt' );
    }
    
    0 讨论(0)
  • 2021-02-20 11:53

    You can reinitialize the datatable by clearing it and then adding the element using fnAddData().

    First check whether the dataTable exists or not. The function fnClearTable() will clear the data from table.

    In the code, dataTable is datatable variable and results is the id of table.

    if(typeof dataTable === 'undefined'){
        dataTable = $('#results').dataTable({ 
           "aLengthMenu": [
               [25, 50, 100, 200],
               [25, 50, 100, 200]
            ], 
            "iDisplayLength" : 25,
            "sPaginationType": "full_numbers",
        }); 
    }else dataTable.fnClearTable();
    

    Then again add the data using fnAddData.

    dataTable.fnAddData( [key, assignee, summary, status, days]);
    
    0 讨论(0)
提交回复
热议问题