fnDeleteRow and server-side processing

fnDeleteRow and server-side processing

pedalshoepedalshoe Posts: 9Questions: 0Answers: 0
edited February 2010 in General
I have a table getting the data from the server. I have sajax4ource specified,
I also have defined fnRowCallback to do an ajax call to update the server side
when a new row is inserted.
So I have a delete button which is to delete rows from the table. Since my data is
All server side I was looking for a hook to the server to process the row removal
When I call oTable.fnDeleteRow()

My code:
[code]
function deleteChecked() {
var checked = $(oTable.fnGetNodes()).find( "input:checked");
for( i=0; i

Replies

  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    Hi Christopher,

    fnGetNodes - yes, it will get all TR elements for the current display (for server side processing that's only what you can see)

    fnDeleteRow - again correct. If you want to delete a row on the server, you need to make the XHR call to do so. The reason DataTables doesn't do this, is because each app will have it's own way of doing this. Once the row has been deleted, just call fnDraw() to reload the table from the server with the updated database. fnDeleteRow (and fnAddData etc) are not designed for server-side processing (where, of course, all the processing has to be done on the server).

    So key thing here is, build an XHR to delete your row, then call fnDraw to update.

    Regards,
    Allan
  • mislead_mattmislead_matt Posts: 3Questions: 0Answers: 0
    I realize how to do this now by reading most of your comments on this subject Allan, but is there any way you could provide a basic XHR request for this?

    I use PHP for the server-side of things, so a basic php/mysql delete snippet of mine would be

    [code]
    $the_id = $_GET['id'];

    $del_query = "DELETE FROM table WHERE id='$the_id'";
    mysql_query($del_query) or die(mysql_error());
    [/code]

    So if that's my basic php file I want to run when someone clicks a 'delete' link in my dataTable.. how do I construct the Ajax request? If it's not too difficult, could you provide an example? Then after that php file is run, where do you call the fnDraw? I'm obviously not good at javascript =[
  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    [code]
    $.getJSON( "detele.php", [ { "key": "id", "value": whatever_id } ], function () { oTable.fnDraw() } );
    [/code]
    Something like that should do.

    Allan
This discussion has been closed.