How to reinitialize jquery Datatable

前端 未结 2 1368
暗喜
暗喜 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: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]);
    

提交回复
热议问题