HOw to get number of rows
HOw to get number of rows
Hello all,
I wanted to know how do I go about getting the number of rows in my datatable.
If I use
var rowCount = document.getElementById('#table-id').getElementsByTagName('tr');
then it does not take into considering the rows on the next pages.
Is there a function that I use to get the # of total rows across all pages?
Thanks,
Pritish
I wanted to know how do I go about getting the number of rows in my datatable.
If I use
var rowCount = document.getElementById('#table-id').getElementsByTagName('tr');
then it does not take into considering the rows on the next pages.
Is there a function that I use to get the # of total rows across all pages?
Thanks,
Pritish
This discussion has been closed.
Replies
oTable.fnSettings().fnRecordsDisplay() will give you the number after filtering has occurred.
Regards,
Allan
But I'm currently using the following, and it seems to work for me.
oTable.fnGetData().length;
Another thing, I wanted to know was if I wanted to pass over some of the table data that was not included in the DOM(in my case, some data from page # 2 of the datatable) in an AJAX call, how would I do the same ?
You can use fnGetNodes() to get all TR elements which will allow you to parse them and modify them as needed. This plug-in might be of use as well: http://datatables.net/plug-ins/api#fnGetHiddenNodes
Allan
Thanks for your prompt reply.
So, let me frame my question correctly again.
This is one of the columns in the HTML table that I'm using datatables plug-in for
...
...
And, currently, I'm using the following code to get the value of the hidden field for each row that has the checkbox checked.
var protCaseInstArray = new Array();
$("#mydivsid").find("input[type='checkbox' name='caseConsent']:checked ~ input[name='protCaseInst']").each(function() {
protCaseInstArray.push($(this).val());
});
It works perfectly fine for rows selected on the first page of my datatable, but does not work if I select rows from the 2nd page onwards.
What would the changes I need to make?
Thanks,
Pritish Devurkar.
$(oTable.fnGetNodes()).find("input[type='checkbox' name='caseConsent']:checked ...
Allan
That works perfectly...and thank you for building such a great plug-in.
I was looking to update a section in my page with the number of rows in the DataTable. However, the table can be reloaded several times (using fnReloadAjax(url)), which is resulting in an incorrect length value...
I'm setting up the new row value after the reload function and I tried with oTable.fnSettings().fnRecordsTotal(), oTable.fnGetData().length (these return 0) and with oTable.fnSettings()._fnRecordsTotal (this always returns the size of the initial table).
Any ideas?
Thanks!
Allan
I was looking at the documentation... I'm using something like:
oTable.fnReloadAjax({},'../browse/${actionBean.hgnc}/enabled', function(){
$('#size').html(oTable.fnSettings().fnRecordsTotal());
}, null);
However this does not reload the data or corrects the value in the #size element... If I just call fnReloadAjax with the data source, the data is loaded but I cannot update the row total...
Any ideas?
Thanks in advance!
I was using a streamlined version of the fnAjaxReload plugin which did not include any support for callback operations... I'm doing the update directly in the plugin and it works...
Problem solved!
I can loop the visible rows using jQuery when I click on an click in a cell.
[code]
function foo(ctrl) {
// (td) (tr) (tbody)
$(ctrl).parent().parent().parent().find('tr').each( function(index) {
// get ID of each row
$(this).attr('id');
}
}
[/code]
This works great except that it only iterates through visible rows (current pagination page)
I can use oTable.fnGetNodes() to get all the rows, but it is the original sort order, and doesn't take into account the possible change in sorting.
Is there a way to iterate through ALL rows, but take into account the current sorting?
Update for anyone reading this - in 1.10 use
page.info()
ordata()
(i.e.table.data().length()
to get information about the number of rows in the table.