Problem with row select and delete example on site
Problem with row select and delete example on site
naturalgoodness
Posts: 3Questions: 1Answers: 0
The following example is not working as expected:
http://www.datatables.net/examples/api/select_single_row.html
When the page first loads (i.e. no rows are selected) then clicking on the delete selected row link does delete rows. I guess this isn't how it meant to be - surely when the page first loads nothing should be selected and clicking the link shouldn't delete anything.
Does anyone know how to modify the code to stop this from happening? Thanks in advance!!
http://www.datatables.net/examples/api/select_single_row.html
When the page first loads (i.e. no rows are selected) then clicking on the delete selected row link does delete rows. I guess this isn't how it meant to be - surely when the page first loads nothing should be selected and clicking the link shouldn't delete anything.
Does anyone know how to modify the code to stop this from happening? Thanks in advance!!
This discussion has been closed.
Replies
The solution is to modify the click handler to something like:
[code]
var anSelected = fnGetSelected( oTable );
if (anSelected.length > 0)
oTable.fnDeleteRow( anSelected[0] );
else
alert('Please select a row...');
[/code]
A few other notes on the "row selection" examples:
1) The "preamble" of the several row selection examples contains the sentence "The example below uses the fnRowCallback()...", but none of them actually include fnRowCallback() in the code.
2) There appears to be 2 ways to pick rows for selection: either go through the aoData list or via jQuery selector ("#example tr"). Under what conditions does one work when the other fails?
3) The selector approach seems overly broad: it assigns 'row_selected' to rows in thead and tfoot as well as tbody. (This doesn't affect the example pages because the example CSS is more restrictive and only applies highlighting to rows in tbody, but this could trip up someone who crafts their CSS from scratch.) I would recommend changing the selector to $('#example tbody tr').