Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82800

Datatable state save

$
0
0

Hi i have only one datatable in a page for which i need to save the state. I am able to change the state with the below code

     $('#details').dataTable( {
            "bPaginate": true,
            "bJQueryUI": true,
             "bAutoWidth": false,
                     "bStateSave": true,
                    "order": [ 5, 'desc' ],
            "sPaginationType": "full_numbers",
            "sDom": '<"right"l><"right"fp>rt<"bottom"i><"clear">'
      } );

Actually i was able to save state with just "bStateSave": true But my problem is the saved state is persisting among different user logins which i dont want to happen. Hence i introduced the below code

                      "fnStateSave": function (oSettings, oData) {
                           localStorage.setItem( 'DataTables_'+userid, JSON.stringify(oData) );
                       },
                     "fnStateLoad": function (oSettings) {
                           return JSON.parse( localStorage.getItem('DataTables_'+userid) );
                      }

in a view that for each user i will have different places in localstorage with a key 'DataTables_'+userid. But i am wrong. The above code is ignored and still whatever state saved for previous user comes when the new user logsin and vice a versa.

After going thru some posts i had included "bServerSide": true. Now i get the below error

"DataTables warning: table id=details - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"

My final code is given below

     $('#details').dataTable( {
            "bPaginate": true,
            "bJQueryUI": true,
             "bAutoWidth": false,
            "bServerSide": true,
                     "bStateSave": true,
                     "fnStateSave": function (oSettings, oData) {
                           localStorage.setItem( 'DataTables_'+path, JSON.stringify(oData) );
                       },
                     "fnStateLoad": function (oSettings) {
                           return JSON.parse( localStorage.getItem('DataTables_'+path) );
                      },
                    "order": [ 5, 'desc' ],
            "sPaginationType": "full_numbers",
            "sDom": '<"right"l><"right"fp>rt<"bottom"i><"clear">'
      } );

I am completely new for jquery and datatables. Please let me know where i am going wrong and what needs to be done. My requirement is to save datatable state for each user seperately in localstorage.


Viewing all articles
Browse latest Browse all 82800

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>