Trying to delete ALL rows permanently
Trying to delete ALL rows permanently
jackkerouac
Posts: 3Questions: 0Answers: 0
Hello,
I am trying to delete ALL the rows in my table permanently when a user clicks a button outside the table. I am using the following code to get the number of table rows and loop through them, but it isn't working.
var oSettings = $('.dataTable').dataTable().fnSettings();
var iTotalRecords = oSettings.fnRecordsTotal();
for (i=0;i<=iTotalRecords;i++) {
$('.dataTable').dataTable().fnDeleteRow(i,null,true);
}
Any ideas?
I am trying to delete ALL the rows in my table permanently when a user clicks a button outside the table. I am using the following code to get the number of table rows and loop through them, but it isn't working.
var oSettings = $('.dataTable').dataTable().fnSettings();
var iTotalRecords = oSettings.fnRecordsTotal();
for (i=0;i<=iTotalRecords;i++) {
$('.dataTable').dataTable().fnDeleteRow(i,null,true);
}
Any ideas?
This discussion has been closed.
Replies
var oSettings = $('.dataTable').dataTable().fnSettings();
var iTotalRecords = oSettings.fnRecordsTotal();
for (i=0;i<=iTotalRecords;i++) {
$('.dataTable').dataTable().fnDeleteRow(0,null,true);
}
So it deletes the first row every time until all of them are gone.
Allan
The fnClearTable() for some reason does not remove rows in my table. I am using dataTables version 1.7.4. This is my initialization function:
[code]
function InitTable ( url , elementname ) {
var T = $(elementname).dataTable( {
"bProcessing": true,
"bPaginate" : false,
"bSort" : false,
"bLengthChange" : false,
"bScrollInfinite" : false,
"sScrollY" : '500px',
"bScrollCollapse": false,
"bFilter": false,
"bServerSide": true,
"sAjaxSource": url
});
return T;
}
[/code]
It loads the data and returns the variable of dataTables object I am able to manipulate, but the method fnClearTable() does not delete rows in the table.
Gustav
If you want to delete all rows from the database, you'll need to make a call to the server to tell it to delete the data, and then redraw the table. The reason for this is that DataTables can't know how your server is set up - so the API functions can only manipulate data on the client side.
Allan
[code]
public function resetAction()
{
echo '{"sEcho":'.intval($_GET['sEcho']).',"iTotalRecords":0,"iTotalDisplayRecords":0,"aaData":[]}';
$this->getHelper('viewRenderer')->setNoRender();
}
[/code]
...and it works like a charm.
Thank you,
Gustav