fnDeleteRow callback -- how to get the deleted row's data?

fnDeleteRow callback -- how to get the deleted row's data?

coencoen Posts: 3Questions: 0Answers: 0
edited July 2011 in General
I am able to delete a row just fine, but I need to do some other stuff with the data from that row. The callback from fnDeleteRow does have an object that resembles the deleted row in the second argument, I discovered, but how to handle that one?

[code]
function removeFromCart(node)
{
item = $(node).parents('tr');
itemName = item.find('td')[0];
itemName = $(itemName).html();
if(confirm("Are you sure you want to delete '"+itemName+"' from your cart?"))
{
basket.fnDeleteRow(item, onRowDeleted);
}
}


function onRowDeleted(dataTable, affectedRow)
{
console.log(affectedRow);
ueid = affectedRow._aData[0];

deleteFormData(ueid);
}
[/code]

As you can see I want the data from the first column in the affected row. How to do this? The callback behavior is not really documented on the API page...

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    get the row data before you call delete.

    if you know the row number to delete, you can use that row number to get the node or data
    fnGetNode(iRowNumber) or fnGetData(fnGetNode(iRowNumber))
  • coencoen Posts: 3Questions: 0Answers: 0
    Yes, but how? the action that needs to be performed must only take place after the node has been deleted. So: a callback. But I can't give data to the callback myself, right? Like this:

    [code]
    basket.fnDeleteRow(item, onRowDeleted(ueid));
    [/code]

    Or something... So how would I do that?
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    How are you deleting the row? before you call basket.fnDeleteRow(), copy the contents of the row using the methods above, then after deletion, you can do whatever you want with it.
  • coencoen Posts: 3Questions: 0Answers: 0
    Look at the code snippet in the start post. removeFromCart() executes the delete API call fnDeleteRow. This function has a callback, onRowDeleted. This callback gets certain data passed to it. Apparently the whole dataTables object first, then the affected row second, as a node.

    Now I want to access the data in that deleted (affected) row once more, to delete a form element in the page that has the idea with the same name as the value of column 0 (first column, hidden) of the deleted row. So my question now is: how do I use the affectedRow node that is defined in onRowDeleted()? How do I access its data?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited July 2011
    What I think you will need to do is call fnGetData() for the target row before calling fnDeleteRow (assuming you want the data outside the callback function - otherwise as you've seen the row data in available as the second parameter).

    An alternative would be to store the data array in a variable with enough scope to be accessed from both the callback and the local function.

    Allan
This discussion has been closed.