Deleting Nodes/tr
Deleting Nodes/tr
When I run this:
[code]
$('.delete').click( function() {
var oTable = $('#demo').dataTable();
var anSelected = fnGetSelected(oTable,'Laf2');
console.log(anSelected);
if ( anSelected.length !== 0 ) {
for(q = 0; q < anSelected.length; q++){
oTable.fnDeleteRow(anSelected[q]);
}
}
[/code]
I have 500 rows showing on the first page, and it deletes all of those with .Laf2 class but it will not delete all of them from the overall table.
Ex: I have 518 .Laf2 classes - when I click this - it will remove 500, but 18 will be left because they were on another page. This is important to my project. It would be great to get some help on it. Thanks.
[code]
$('.delete').click( function() {
var oTable = $('#demo').dataTable();
var anSelected = fnGetSelected(oTable,'Laf2');
console.log(anSelected);
if ( anSelected.length !== 0 ) {
for(q = 0; q < anSelected.length; q++){
oTable.fnDeleteRow(anSelected[q]);
}
}
[/code]
I have 500 rows showing on the first page, and it deletes all of those with .Laf2 class but it will not delete all of them from the overall table.
Ex: I have 518 .Laf2 classes - when I click this - it will remove 500, but 18 will be left because they were on another page. This is important to my project. It would be great to get some help on it. Thanks.
This discussion has been closed.
Replies
If you fancy giving 1.10-dev a go you could do:
[code]
$('#demo').DataTable().rows( 'tr.Laf2' ).remove().draw();
[/code]
assuming when you say "class" you mean it is applied to the `tr` element?
Allan
I will give 1.10 a try - do you have a link to load it through CDN?
I want to delete all rows, on any page of my results that have the .Laf2 class. I figured there would be fnGetNodes method or function to do this.
[code]
function fnGetSelected( oTableLocal,loc )
{
return oTableLocal.$('tr.'+loc);
}
[/code]
Not yet. There will be when it goes beta.
The method you are using at the moment should work, unless you are using server-side processing of course.
Allan
It depends upon your DataTables initialisation. Can you please link to a test page, or use the debugger so I can see how you are using DataTables and be able to help further.
Allan
Try this. Hit create - then Filter with 'Laf 2' - there will be 560 results. then hit delete. It will delete 500 but leave 60, it's deleting based on the class. Looking at the console output, it looks like the classes 'Laf2' are not added until it's displayed on the page.
Should that not be:
[code]
var tr = $(nodes).filter('.Laf2')[0];
[/code]
?
Allan
[code]
function subtotal_calculate(field,i,stem){
/* Add a 3rd varible that represents the type of Sum, such as Location or MID*/
var oTable = $('#demo').dataTable();
var data = oTable.fnGetData();
var subtotal = 0;
if(stem == 'Location'){
var selection_current = selected_locations[i];
} else {
var selection_current = selected_mids[i];
}
for(w = 0; w < data.length; w++){
if(data[w].User == ''){
console.log(data[w][field]);
} else {
var value_check = data[w][stem];
if(value_check == selection_current){
//console.log(data[w][field]);
subtotal += eval(data[w][field]);
}
}
}
return subtotal;
}
[/code]