Trying to send the Form Data which is called as dataValues and other values defined in d

Trying to send the Form Data which is called as dataValues and other values defined in d

maniyamaniya Posts: 78Questions: 13Answers: 0

I have situation where i am trying to fetch the data from the cfm file but it is not sending the formvalues to the server so it can process and send me the data back and i can refresh my datatables again

var parentAjaxTable = $('#tblData').DataTable({
    ajax: {
        url: 'data.cfm',
        type: 'POST',
        data: function(d) {
          d.section = 'rowUpdate';
          d.urlstatus = urlstatus; // You'll need to define _status or pass it as a parameter
          d.dformat = $('.application').attr('data-format').toUpperCase();
          return d;
        },
        dataSrc: function(json) {
          // Modify the data returned from the server to include dataValues
          json.dataValues = dataValues;
          return json.data;
        }
    },
    columns: [
        { data: "CheckBoxIcon" },
        { data: "Employee" },
        { data: "Type" },
        { data: "weekending" },
        { data: "Submission_Date" },
        { data: "Approved/Rejected By" },
        { data: "Date Approved" },
        { data: "Totalhours" },
        { data: "viewIcon" }
    ]
});

function reqUpdate(dataValues, type, rowID, _status) {
  var table = $('#tblData').DataTable(); // Get the DataTable instance
  // Update the data source parameters
  table.ajax.url('data.cfm?section=rowUpdate&urlstatus=' + _status).load(function(json) {
    // Perform actions after the table has been updated
    // For example, you can update the table data using the dataValues
    table.clear();
    table.rows.add(dataValues);
    table.draw();
  }, false); // Set the second parameter to false to prevent the table from being redrawn automatically

  // Get the current data from the DataTable
  var currentData = table.ajax.params().data;

  // Merge the current data with the new dataValues
  var mergedData = Object.assign({}, currentData, dataValues);

  // Send the merged data along with the AJAX request
  table.ajax.reload(null, false); // The second parameter is set to false to prevent the table from being redrawn automatically
}

i am trying different techniques but unable to send the dataValues to the server, not sure what is going wrong in here, please guide

Answers

  • allanallan Posts: 63,439Questions: 1Answers: 10,459 Site admin

    It seams like it should be POSTing section, urlstatus and dformat values to the data.cfm route. If that isn't working, can you link to a page showing the issue please.

    Allan

  • maniyamaniya Posts: 78Questions: 13Answers: 0

    i do not have a page, its intranet website but i confirm that only url which is rowUpdate and urlstatus is going to the data.cfm, no post is pushed

  • kthorngrenkthorngren Posts: 21,292Questions: 26Answers: 4,944

    Use the browser's network inspector to get the Payload sent. Please paste the payload into the thread so we can see the request sent.

    Kevin

  • maniyamaniya Posts: 78Questions: 13Answers: 0

    This is the Payload which is sent

    section=rowUpdate&urlstatus=r&_=1713530632701

    i updated a function a little bit to do everything in one call

    function reqUpdate(dataValues, type, rowID, _status) {
     // Use parentAjaxTable instead of creating a new DataTable instance
    
      var parentAjaxTable = $('#tblData').DataTable({
          ajax: {
              url: 'data.cfm',
              type: 'POST',
              data: function(d) {
                d.section = 'rowUpdate';
                d.dformat = $('.timesheet_application').attr('data-format').toUpperCase();
                d.dataValues = dataValues;
                console.log(d);
                return d;
              },
              dataSrc: function(json) {
                // Modify the data returned from the server to include dataValues
                json.dataValues = dataValues;
                return json.data;
              }
          },
          columns: [
              { data: "CheckBoxIcon" },
              { data: "Employee" },
              { data: "Type" },
              { data: "weekending" },
              { data: "Submission_Date" },
              { data: "Approved/Rejected By" },
              { data: "Date Approved" },
              { data: "Totalhours" },
              { data: "viewIcon" }
          ]
      });
    
     var table = parentAjaxTable; // Get the DataTable instance
    
     // Update the data source parameters
     // Note: Since parentAjaxTable is already configured with an ajax option, you might not need to set the url again.
     // However, if you need to update the parameters dynamically, you can do so here.
     // For demonstration, I'm setting the url again, but in practice, you might just need to update the dataValues.
     table.ajax.url('data.cfm?section=rowUpdate&urlstatus=' + _status).load(function(json) {
        // Perform actions after the table has been updated
        // For example, you can update the table data using the dataValues
        table.clear();
        table.rows.add(dataValues);
        table.draw();
     }, false); // Set the second parameter to false to prevent the table from being redrawn automatically
    
     // Get the current data from the DataTable
     var currentData = table.ajax.params().data;
    
     // Merge the current data with the new dataValues
     var mergedData = Object.assign({}, currentData, dataValues);
    
     // Update the data source parameters with the merged data
     table.ajax.data(mergedData);
    
     // Reload the table with the updated data source parameters
     table.ajax.reload(null, false); // The second parameter is set to false to prevent the table from being redrawn automatically
    }
    
  • kthorngrenkthorngren Posts: 21,292Questions: 26Answers: 4,944

    In lin 40 you are doing this:

     table.ajax.url('data.cfm?section=rowUpdate&urlstatus=' + _status).load(function(json) {
    

    Possibly you will want to use ajax.reload() instead to take advantage of the ajax config.

    Kevin

Sign In or Register to comment.