Problems with Delete Row
Problems with Delete Row
mvillavicencio
Posts: 6Questions: 0Answers: 0
Good afternoon. I'm using this and it's awesome! But I have a problem implementing the click handler for Delete row. I'm obtaining the data from server, the javascript code is written bottom.
I called the delete function in the html page:
Delete selected row
But it seems that I can't obtaining the row selected. I probed introducing "alert( anSelected[0] );" in the delete function to see what parameter I'm receiving, but the message that it displays is "[object HTMLTableRowElement]", instead the row.
Please your help! I would appreciate a lot!
var oTable;
var giRedraw = false;
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/serverprocessing.php"
} );
/* Add a click handler to the rows - this could be used as a callback */
//$("#example tbody").click(function(event) {
$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
/* Add a click handler for the delete row */
$('#delete').click( function() {
var anSelected = fnGetSelected( oTable );
alert( anSelected[0] );
oTable.fnDeleteRow( anSelected[0] );
} );
/* Init the table */
var oTable = $('#example').dataTable( );
} );
/********************* */
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i
I called the delete function in the html page:
Delete selected row
But it seems that I can't obtaining the row selected. I probed introducing "alert( anSelected[0] );" in the delete function to see what parameter I'm receiving, but the message that it displays is "[object HTMLTableRowElement]", instead the row.
Please your help! I would appreciate a lot!
var oTable;
var giRedraw = false;
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/serverprocessing.php"
} );
/* Add a click handler to the rows - this could be used as a callback */
//$("#example tbody").click(function(event) {
$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
/* Add a click handler for the delete row */
$('#delete').click( function() {
var anSelected = fnGetSelected( oTable );
alert( anSelected[0] );
oTable.fnDeleteRow( anSelected[0] );
} );
/* Init the table */
var oTable = $('#example').dataTable( );
} );
/********************* */
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i
This discussion has been closed.
Replies
Allan
var anSelected = fnGetSelected( oTable );
alert( anSelected[0] );
you can use fnGetPosition(anSelected[0]) to get the index of the row within DataTables
fnDeleteRow can accept either the DOM row or the index of the row.
var anSelected = fnGetSelected( oTable );
var aPos = oTable.fnGetPosition(anSelected[0]);
var aData = oTable.fnGetData( aPos,here_the_number_of_column );