c# - How to re-initialize DataTable in Jquery -
i have requirement in have store state of datatable 'pagination', 'sorting', 'search' etc. have set 'bstatesave' property 'true' , working pretty well. know 'bstatesave' save state in form of cookie. have requirement in have reset datatable , reinitialize in case of user login.
forex:
if (sessionuserlogin == 'true') { $('#mytableid').datatable({ "bstatesave": false, "bdestroy": true}); $('#mytableid').datatable({ "bstatesave": true }); } else { $("#mytableid").datatable({ "bstatesave": true }); }
as per above example "sessionuserlogin" tells if user login system, if flag(sessionuserlogin) sets true, want destroy previous state , initialize table again can continue saving state. else condition used handle other postbacks in system after login of user want maintain state of table after postbacks dropdown change or saving records.
my above code works fine when user login, able clear state of table, not able initialize table state again.
i have gone through url. still not able find solution.
please help. in advance.
you can try using destroy
method below
var table = $('#mytable').datatable(); if (sessionuserlogin == 'true') { table.destroy(); $('#yourtableid').empty(); $('#yourtableid').datatable( { "bstatesave": true }); } else { $("#yourtableid").datatable({ "bstatesave": true }); }
edit
var table = $('#mytable').datatable(); if (sessionuserlogin == 'true') { table.destroy(); $('#yourtableid').empty(); table = $('#yourtableid').datatable( { "bstatesave": true }); } else { table = $('#yourtableid').datatable( { "bstatesave": true }); }
Comments
Post a Comment