Reputation: 375
I'm using jQuery datatables to manage a list o firms.
Everything is working great, except the part where I have to delete a row.
For the first row deleted is working great, but if I delete another row in my firefox console it displays the first row deleted and this one.
If I delete a third row it displays all the rows deleted.
$s('body').on('click', '.del-firm', function(){
var aPos = oTable.fnGetPosition( $s(this).closest('tr')[0] );
var firm = $s(this).data('firm');
$s('#client-firms').block({
message: $s('.confirm-block'),
overlayCSS: {
backgroundColor: '#363636',
cursor: 'default'
},
css : {
border: '1px solid #D0D0D0',
background: 'linear-gradient(to bottom, #fcfcfc 0%, #fbfbfb 39%, #eeeeee 84%, #ebebed 100%) repeat scroll 0 0 rgba(0, 0, 0, 0)',
borderRadius: '3px',
color: '#707070',
padding: '5px',
cursor: 'default'
}
});
$s('#yes').click(function(){
$s('#client-firms').block({
message: 'Se proceseaza'
});
oTable.fnDeleteRow(aPos);
$s.ajax({
type: 'post',
url: 'index.php?controller=servlet&method=del_firm',
data: {
'id': firm
},
success: function(data){
$s('#client-firms').unblock();
}
});
newRow = false;
});
$s('#no').click(function(){
$s('#client-firms').unblock();
return false;
});
});
Upvotes: 1
Views: 618
Reputation: 274
I would do so:
$s('#client-firms').on('click', '.del-firm', function(){
$s(this).closest('tr').addClass('selected');
var firm = $s(this).data('firm');
var row = $s('#client-firms').find('.selected');
$s('#client-firms').block({
message: $s('.confirm-block'),
overlayCSS: {
backgroundColor: '#363636',
cursor: 'default'
},
css : {
border: '1px solid #D0D0D0',
background: 'linear-gradient(to bottom, #fcfcfc 0%, #fbfbfb 39%, #eeeeee 84%, #ebebed 100%) repeat scroll 0 0 rgba(0, 0, 0, 0)',
borderRadius: '3px',
color: '#707070',
padding: '5px',
cursor: 'default'
}
});
$s('#no').click(function(){
$s('#client-firms').unblock();
return false;
});
});
$s('#yes').on('click' , function(){
var row = $s('#client-firms').find('.selected');
var firm = row.find('.del-firm').data('firm');
$s('#client-firms').block({
message: 'Se proceseaza'
});
$s.ajax({
type: 'post',
url: 'index.php?controller=servlet&method=del_firm',
data: {
'id': firm
},
success: function(){
$s('#client-firms').unblock();
oTable.row(row).remove().draw();
}
});
newRow = false;
oTable.draw();
});
Upvotes: 2