How to store client side rendered columns data in to database ?

How to store client side rendered columns data in to database ?

Shivani VyasShivani Vyas Posts: 113Questions: 11Answers: 0

How to store client side rendered data in to database ? I have two columns in my table which I rendered client side. Now I want to store those rendered data in to database. Currently all other columns works perfectly when I edit values, it stores updated values back into database but not those column which I rendered.

I come across below ajax option but looking for proper example. Below example is more like syntax and not sure how to stroed two or more rendered column's data using this function. Please advice and direct me to any thread or question if already answered.

$('#example').dataTable( {
  "ajax": function (data, callback, settings) {
    callback(
      JSON.parse( localStorage.getItem('dataTablesData') )
    );
  }
} );

Here is my rendered columns code:

var table = $('#assyntCx_Table').DataTable( {
    dom: "lBfrtip",

    //For SAT Forecast
    orderFixed: [[0, 'asc'], [1, 'asc']],

    drawCallback: function(){

        var api = this.api();
        var result = {};


        // Loop all cells in Location column
        api.cells(null, 0).every( function (rowIdx){
            var data = this.data();

            if( ! result.hasOwnProperty( data)){

                result[data] = 0;
            }


        // Get the TSSA Forecast date from the same row

          var Tssa = api.cell( rowIdx, 36).render( 'display' );

        // Keep track of latest Tssa date
          if ( result[data] < moment(Tssa) )
          {

            result[data] = moment(Tssa);

          }

    });

    //console.log(result);

    var currentLocation = ''; // Keep track of Location changes

    // Loop through all the rows and store the lates date, per Locaiton, +14 days

    api.cells(null, 0).every( function (rowIdx){

        var data = this.data();

      // If Location changes then update tracker and reset increment counter

        if (data !== currentLocation ) {

        currentLocation = data;
        incrementCounter = 14;

        }

        var ans = moment( result[data]).add(incrementCounter, 'days');
        incrementCounter++; 

        api.cell( rowIdx, 42).data(moment(ans).format('DD MMM YYYY'));


    });
  },



    //AJAX
    //serverSide: true,
    processing: true,
    ajax: {
      url: "../ajax/at/elevators.php",
      type: "POST",
      deferRender: true,
    },

    //TABLE WINDOW
    scrollY:        "65vh",
    scrollX:        true,
    scrollCollapse: false,
    paging:         true,
    fixedColumns:   {
      left: 3
    },

    columns: [


{ data: "TIDForecast", // - TSSA Forecast Calculation

         render : function(data,type,row){

             if((row.SIForecast == null) && (row.SIActual == null)){

                 return null;
             }

             var SIF = moment(row.SIForecast).add(98, 'days'); // Start Install Forecast
             var SIA = moment(row.SIActual).add(98, 'days'); // Start Install Actual

             // IF ACTUAL IS EMPTY USE FORECAST.
             // IF ACTUAL IS NOT EMPTY USE ACTUAL.


                if(row.SIActual == null)
                {
                    return SIF.format('DD MMM YYYY'); // Add 98 Days into SIForecast Date
                }
                else                             
                {
                    return SIA.format('DD MMM YYYY'); // Add 98 Days into SIActual Date
                }


            }

      },

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    How to store client side rendered data in to database ?

    You don't - they are client-side. You would need to recreate them on the server-side - either using a script in whatever programming environment you are using (looks like PHP in this case), or using SQL.

    If you must use the client-side created value, you'd need to edit each row in turn, calculate the value and submit it as a regular field (possibly hidden since it is automatically calculated).

    Allan

Sign In or Register to comment.