Is there a way to use "bServerSide": true along with fnAddData?

Is there a way to use "bServerSide": true along with fnAddData?

mixcalmixcal Posts: 7Questions: 0Answers: 0
edited August 2011 in General
Hi Allan,

I really love the plugin and it's very useful.

I intend to use it as detail grid transactional module(purchase/sales).

When i'm editing a transaction at first i'll need bServerSide:true so i can load the data. But due to that, i can't use fnAddData as it keeps refreshing the datatables, even with fnAddData( data, false), the data still wont be added.

Is there a way to work around this? found similar thread to this but the i can't apply the solution as this is transactional with header-detail so need to be submitted together(all the details and header).

Thanks in advance!

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited August 2011
    you'll need to send the data to a server side script to add to the database. you can use an AJAX call
    http://api.jquery.com/jQuery.ajax/

    [code]
    $.ajax({
    url: "serverscript.php", // whatever the name/url of your script is
    data: { "id": idvalue, "value": value}, // data to POST or add to querystring of your url.. for an entire row of data, add more parameters or make the value a string of items concatenated. however you want to handle
    dataType: "json", // if you want the return data to be JSON, or xml, script, or html
    //type: "POST", // commend this out to GET. or uncomment to POST the data
    error: function(jqXHR, textStatus, errorThrown) { }, // error handler
    success: function(data, textStatus, jqXHR) { } // success callback
    });
    [/code]
  • mixcalmixcal Posts: 7Questions: 0Answers: 0
    Hi fbas,

    I'm looking to add data on client side using fnadddata but i dont want it to auto redraw the table until I need it to.
    I try using fnAddData(data,false), when i check it using fnGetData, the data is added but it's not displayed on the datatables.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    it's not displayed because you didn't want it to draw the table. you can call fnDraw (or install the plugin function fnStandingRedraw) when you want to display the changes
  • mixcalmixcal Posts: 7Questions: 0Answers: 0
    already found my solution

    i set datatables().fnSettings().oFeatures.bServerSide to false prior to fnAddData
    and return it to true after fnAddData.

    thanks for the reply :D
  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    The would work to display it on the client-side, but it will be lost on the next draw (filtering, paging, sorting etc) unless you add it to the server-side data source, since that is where the data is held (the way fbas suggests is spot on).

    With server-side processing DataTables is really no more than a display and event handler.

    Allan
  • mixcalmixcal Posts: 7Questions: 0Answers: 0
    Yes, I'm aware of it =D

    i'm just looking to use it as temporary table for displaying purchase detail which will be submitted to server all at once upon submit button trigger.
This discussion has been closed.