Cannot delete last row

Cannot delete last row

rsreaganrsreagan Posts: 7Questions: 0Answers: 0
edited December 2010 in General
I've created a table with a delete link in each row. The table looks something like this:

[code]



Some Data
Delete



[/code]

In my $(document).ready, I have the following code:

[code]
$('#theTable tr td span.deleteLink').click(function () {
var row = $(this).parent().parent();
//locationsTable is the name of my DataTable that I've created.
locationsTable.fnDeleteRow(row);
});
[/code]

This does what I'd expect on every row except for the last row that exists in the table. When I click the Delete link on the last row in the table, nothing happens. The code above doesn't even give me a Javascript error. It doesn't matter which order I delete the rows in - the results are the same.

I'm obviously missing something important, and probably something simple. Any help would be appreciated.

By the way, this is a beautiful plug-in.

-Rob

Replies

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    Hi Rob,

    Thanks for the kind words. My first thought is that you might have 11 rows, and this be run after the DataTables initialisation? You might want to use live events like this: http://datatables.net/examples/advanced_init/events_post_init.html . You can use Visual Event to confirm if the row has an event listener on it: http://sprymedia.co.uk/article/Visual+Event .

    Allan
  • michal404michal404 Posts: 1Questions: 0Answers: 0
    edited January 2011
    I am experiencing the same problem. However it is unclear from the the example that you provided on how to use the fnGetNodes in the case of row deletion . I can confirm that the event listener is present on the last row.

    I got around the problem by not using jquery selector (for some strange reason this var row = $(this).parent().parent(); will not work - it results in failure to determine node name (tr or td)) but this works:

    [code]nNode = (this.parentElement).parentElement;[/code]
This discussion has been closed.