statesave:true is not working ??

statesave:true is not working ??

karamkaram Posts: 31Questions: 14Answers: 0

1.10.9 version state save :true is not working when using statesavecallback in script ? individually its working for local storage.

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    stateSave appears to work well in this example.

    Please link to a test case showing the issue, as per the forum rules.

    Allan

  • karamkaram Posts: 31Questions: 14Answers: 0

    save state true is working fine for browser level... but when i try to use it with savestatecallback method it stops working at browser level.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Can you link to a test case showing the issue, as I requested before please.

    Allan

  • karamkaram Posts: 31Questions: 14Answers: 0
    edited November 2015

    //to get column settings
    $.fn.getColumnsShown = function(dTable)
    {
    vCols = "";
    $.each(dTable.fnSettings().aoColumns, function(c){
    if(dTable.fnSettings().aoColumns[c].bVisible == true){
    vCols = vCols + dTable.fnSettings().aoColumns[c].sName +"|";
    }
    });
    return vCols;
    }

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

         table= $('#exampletable).DataTable( {  
                    "processing": true,                
                    "deferRender": true,            
    
                     dom:'<"clear"BRlfrtip>',
                                         buttons: [
                                {  extend: 'colvis',
                                    text: 'Change Layout',
                                    collectionLayout: 'fixed four-column',  
    
                                } ,
    
                    "ajax": {
                                "url": "/ mypage.so",
                                "type": "GET"   
    
                                 },
    
                    "stateSave": true,                   
                     "stateSaveParams": function (settings, data) {                         
                           data.columnStr =  $('#exampletable).getColumnsShown(this);
                           //data.search.search = "";
    
                          },                     
                     "stateSaveCallback": function (settings, data) {
                            // Send an Ajax request to the server with the state object 
                            $('#save').on('click', function (e) {
                            $.ajax( {
                              "url": "/example1.so",
                              "data": data,
                              "dataType": "json",
                              "type": "POST",
                              "success": function () {}
    
                            } );
                            e.preventDefault(); 
                           // location.reload(true);
                            });                      
    
                          },
    
    
    
                          "stateLoadCallback": function (settings) {
                                var o;                          
                                // Send an Ajax request to the server to get the data. Note that
                               // this is a synchronous request since the data is expected back from the
                                // function
                                //Setting async to false means that the statement you are calling has to complete before the next statement in your function can be called.
                                $.ajax( {
                                  "url": "/example2.so",
                                  "async": false,
                                  "dataType": "json",
                                  "success": function (json) {
                                    o = json;
                                  }
    
    
                                } );
    
                                return o;
                              },
    

    "columns": [{
    "title": "name",
    "data": "name",
    "name": "name"
    }, {
    "title": "addeddate",
    "data": "addeddate",
    "name": "added date"
    }]
    });

  • karamkaram Posts: 31Questions: 14Answers: 0

    also statesaveload is not working on page laod

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    This is the last time I'll request a link to a test case to a page showing the issue. If you can't host the page yourself please use JSFiddle, CodePen or http://live.datatables.net .

    Allan

This discussion has been closed.