Getting row`s id to delete it via its button.

Getting row`s id to delete it via its button.

fgonzalezfgonzalez Posts: 1Questions: 0Answers: 0
edited November 2012 in General
Hi. I am showing a dataTable with a delete button on one of its columns. As I click on it i would like have a confirmation message and afterwards being able to send the row`s id to my action class. I´m working with jsp.

Thanks in advance

Replies

  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    Hope this helps.

    nth-child[10] - Assumed column of Delete Button

    [code]
    $("#exampletd:nth-child(10)").live("click", function (e) {
    e.preventDefault();

    var nRow = $(this).parents('tr')[0];

    var nTr = this.parentNode;

    var aData = oDetailTable.fnGetData( nTr );

    // Get the key value for delete operation
    var key = aData[0];

    // Prompt the user before deletion -> You can use whatever confirmation method you want
    bootbox.confirm("Are you sure of deleting the invoice - " + invoiceNumber + " ?", function(result) {
    if (result) {
    // Delete the row based on the index value retrieved above
    /*
    Note: If you have records in database for the selected record, it would be ideal to
    i - Either set a flag in the table for the selected record so that it wont be selected and displayed in the dataTable again
    (Called Soft Delete)
    ii - Do a delete on the table
    call fnDraw() after successful delete / soft delete in the table
    */

    } else {
    console.log("Relax. Think hard next time before deleting");
    }
    });
    });
    [/code]
This discussion has been closed.