Deleting row after successful response from Jquery post

Deleting row after successful response from Jquery post

peterbrapeterbra Posts: 7Questions: 0Answers: 0
edited September 2012 in General
I am noob at Jquery and all that stuff, so please help me a bit :)

This is delete function I am using to delete record from MySQL:
[code]
function DeletePublisher(publisherid) {
jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function(r) { if (r)
$.ajax({
type: "POST", //or GET
url: 'includes/publishers/delete-publisher.php?publisherid=' + publisherid,
data: '',
success: function(response){
$.jGrowl('Publisher deleted');
window.location.reload();
}
});
});
}
[/code]

I am displaying table like this:
[code]
...A LOT OF COLUMS...
<?php echo $publisher_unpaid; ?>


Edit
Delete


[/code]

Now all this works OK, but, as you may see, I do a refresh in order to update table, but can't figure out HOW TO DELETE only that particular row (so not to refresh whole page all the time ?)... I just don't know how to implement fnDeleteRow in this case :(

Thanks !

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    How have you tried to use it? This will delete the first row for example:

    [code]
    t.fnDeleteRow( $('#myTable tbody tr:eq(0)')[0] );
    [/code]

    Allan
  • peterbrapeterbra Posts: 7Questions: 0Answers: 0
    Allan, I see that, but my biggest problem is that I don't want to remove the first row, but the one where delete button was clicked. So I am not sure how to get the ID of that ? Thanks.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    That was just an example of how fnDeleteRow works - I presumed you have a reference to the row. Can you not just store it in a variable (you must have it if you've got an event on it) and then pass it into fnDeleteRow?

    Allan
  • peterbrapeterbra Posts: 7Questions: 0Answers: 0
    Well, as I said - I am noob at Jquery stuff, and not sure how to pass the variable. OnClick event - I am passing id of the MySQL row to external script that deletes it from DB (as you see it's Jquery post/get), and if success if triggers the Alert (Successfully Deleted ). Now my dilemma is how to pass (within the same OnClickEvent) DataTable row id... Also I am not sure HOW TO GET the DataTable row id at the first place. Sorry for beeing noob :(
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    edited September 2012
    [code]
    $('#myTable tbody').on( 'click', 'tr', function () {
    var tr = this;

    $.ajax( {
    ...
    success: function () {
    t.fnDeleteRow( tr );
    }
    } );
    } );
    [/code]

    where `t` is the DataTables instance.

    Allan
This discussion has been closed.