Login | Register | FAQ
Anonymous

how to delete selected row from data tabel

+ Post a reply

2 posts Page 1 of 1


how to delete selected row from data tabel

by innamhunzai » Mon Jun 18, 2012 12:05 am

Hello, I am new to web development ….. I am having problem in deleting selected row from data table ….. I am using datatabels jquery plugin following is the initialization code…. I want to know how to send ajax request to php script so that it delete the selected row from the database ….

var oTable;

$(document).ready(function() {
/* Add a click handler to the rows – this could be used as a callback */
$(“#example tbody tr”).click( function( e ) {
if ( $(this).hasClass(‘row_selected’) ) {
$(this).removeClass(‘row_selected’);
}
else {
oTable.$(‘tr.row_selected’).removeClass(‘row_selected’);
$(this).addClass(‘row_selected’);
}
});

/* Add a click handler for the delete row */
$(‘#delete’).click( function() {
var anSelected = fnGetSelected( oTable );
if ( anSelected.length !== 0 ) {
oTable.fnDeleteRow( anSelected[0] );
}
} );

/* Init the table */
oTable = $(‘#example’).dataTable( );
} );

/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
return oTableLocal.$(‘tr.row_selected’);
}
User avatar

innamhunzai

  • Posts: 1
  • Joined: Mon Jun 18, 2012 12:01 am

Re: how to delete selected row from data tabel

by XainPro » Mon Jun 18, 2012 4:38 am

add a column in a table and add a image of cross in all cells and give it a class of delete after that just put this code in your java script and do remember to call Jquery first
try this
Code: Select all
$("table td img.delete").click(function () {
    $(this).parent().parent().parent().fadeTo(400, 0, function () {
        $(this).remove();
    });
    return false;
});
User avatar

XainPro

  • Posts: 3669
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

Page 1 of 1