javascript - How to reinitialize jquery Datatable -
how reinitialize jquery datatable? tried remove table element. still table displaying. code this:
function removeexistingdatatablereference(tableid) { if(otable !=null) { otable.fndestroy(); } if(document.getelementbyid(tableid)){ document.getelementbyid(tableid).innerhtml=""; } otable=null; try { if(otable !=null) { //otable.fndestroy(); alert("error in fndestroy"); } otable=null; if(document.getelementbyid(tableid)){ document.getelementbyid(tableid).innerhtml=""; } if(document.getelementbyid("ftable")) { removeelement(document.getelementbyid("ftable")); } } catch(e) { alert("error happend:"+e.message); } } function removeelement(element) { try { var elem = document.getelementbyid('ftable'); elem.parentnode.removechild(elem); //ert(element.parentnode.id); //element.parentnode.removechild(element); alert("removed"); return true; } catch(e) { alert(e.message); } return false; }
how can that? after search button click table loaded. again, when search search parameter, table should load new data. not happening. how fix it??
table initialized this:
function createdatatable() { try { 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"]] } ); new fixedcolumns( otable, { "ileftcolumns": 1, "irightcolumns": 1 } ); } catch (e) { alert(e.message); } }
you can reinitialize datatable clearing , adding element using fnadddata()
.
first check whether datatable
exists or not. function fncleartable()
clear data table.
in code, datatable
datatable variable , results
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 data using fnadddata.
datatable.fnadddata( [key, assignee, summary, status, days]);
Comments
Post a Comment