Populate Datatable with Ajax call

回眸只為那壹抹淺笑 提交于 2019-12-06 05:33:30

I was having the same problem...I solved by destroying the table each time I need to reload it. I adapted my code to work with yours, so will be something like:

$(document).ready(function(){
  var oTable;

  //reloading table when the button is clicked
  $('#btnShowExEmpList').click(function(){

    //if the table already exists, destroy it
    if (oTable){
      oTable.fnDestroy();
    }

    //initializing the table
    oTable = initTable();
  });

  //initializing the table automatically when the page loads
  $('#btnShowExEmpList').click();
});

And I also think that instead using your success option to reload the data, would be easier if you set some options for your datatable (bServerSide, sAjaxSource, fnServerData, etc).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!