最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Saving state and column sort in DataTable. (using a cookie) - Stack Overflow

programmeradmin6浏览0评论

I'm trying to make sure state of a DataTable is saved in a cookie so when page is reloaded it maintains the sort order of fields. This is my code, but bStateSave seems to be having no effect whatsoever.

I followed the method described here: .html.

What am I doing wrong? Will appreciate help!

tbl = $(selector).dataTable({
           "bStateSave": true,
           "bProcessing": true,
           "bServerSide": true,
           "sAjaxSource": dataSource,
           "iDeferLoading": totalRecCount,

           "sDom": layout ? layout : defaultLayout,
                   "fnDrawCallback": drawCallback,
                   "aoColumns": aoColumns,
                   "oLanguage": {
                   "sSearch": ""
           }
       });

I'm trying to make sure state of a DataTable is saved in a cookie so when page is reloaded it maintains the sort order of fields. This is my code, but bStateSave seems to be having no effect whatsoever.

I followed the method described here: http://datatables/examples/basic_init/state_save.html.

What am I doing wrong? Will appreciate help!

tbl = $(selector).dataTable({
           "bStateSave": true,
           "bProcessing": true,
           "bServerSide": true,
           "sAjaxSource": dataSource,
           "iDeferLoading": totalRecCount,

           "sDom": layout ? layout : defaultLayout,
                   "fnDrawCallback": drawCallback,
                   "aoColumns": aoColumns,
                   "oLanguage": {
                   "sSearch": ""
           }
       });
Share Improve this question edited Sep 24, 2013 at 4:09 madth3 7,34412 gold badges52 silver badges74 bronze badges asked Nov 9, 2012 at 13:59 Ravish BhagdevRavish Bhagdev 9551 gold badge13 silver badges27 bronze badges 2
  • Try removing as many of the other settings as you can, then re-add them one by one. – Blazemonger Commented Nov 9, 2012 at 14:05
  • The cookie is named using the tableId + the URL. Can you use chrome dev tools > resources > cookies > to check what cookies are being created? – barry Commented Nov 9, 2012 at 16:06
Add a ment  | 

1 Answer 1

Reset to default 5

OK, I found the answer here: http://datatables/forums/discussion/ment/41588

In short it will not work when using iDeferLoading. Will have to maintain that state manually using a cookie which gets created and updated everytime the user sorts or store it elsewhere in the user model.

发布评论

评论列表(0)

  1. 暂无评论