how to save state in database?

how to save state in database?

karamkaram Posts: 31Questions: 14Answers: 0

I saw this post https://datatables.net/forums/discussion/3700/colvis-get-list-of-hidden-or-shown-columns before that I was trying this one ,https://datatables.net/forums/discussion/18337/complete-example-for-server-side-colreorder-colvis-tabletools-column-filtering-and-state-save can you help me to solve similar one for me also , I need to save column visibility an column reordering state of columns in database by using ajax url, also I am using spring+jpa+ mvc , can you provide me a example that how to get these all states and save in database of table preference table. I have one table which has data and another one is preference table which has one column called prefrences in which I need to save all columns name which are visible or user settings . thanks in advance.
can I use this code for this task somehow ?

    <script language="JavaScript">

//get visible columns
$.fn.getColumnsShown = function(dTable)
{
vCols = new Array();

         $.each(dTable.fnSettings().aoColumns, function(c){
         if(dTable.fnSettings().aoColumns[c].bVisible == true){
         vCols = vCols.concat(dTable.fnSettings().aoColumns[c].sName)
         }
         });

         return vCols;
         }
        $(document).ready( function () {            

            var table;
         table= $('#example).DataTable( {
                    "processing": true,
                    "deferRender": true,
                    "serverSide": true, 
                    //"searching": false,
                    // stateSave: true,


                     "stateSaveCallback": function (settings, data) {
                            // Send an Ajax request to the server with the state object
                            $.ajax( {
                              "url": "/example.so",
                              "data": data,
                              "dataType": "json",
                              "type": "POST",
                              "success": function () {}
                            } );
                          },
                          "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
                                $.ajax( {
                                  "url": "/example.so",
                                  "async": false,
                                  "dataType": "json",
                                  "success": function (json) {
                                    o = json;
                                  }
                                } );
                                return o;
                              },
 "fnServerData": function ( sSource, aoData, fnCallback ) {

                                     columnsShown = $('#example).getColumnsShown(this);
                                     alert(columnsShown);
                                     aoData.push( { "name": "visColumns", "value": columnsShown } );
                                     $.getJSON( sSource, aoData, function (json) {                  
                                     fnCallback(json)
                                     } );
                                     }

Answers

This discussion has been closed.