Cannot delete last row
Cannot delete last row
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
[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
This discussion has been closed.
Replies
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
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]