[server side] get number of rows

[server side] get number of rows

nm_alexnm_alex Posts: 26Questions: 0Answers: 0
edited January 2011 in General
Dear all!

I get some data via server side:
[code]
oTable = $('#oxarticles').dataTable({
"bProcessing": true,
"sAjaxSource": 'bin/dcut_get_list.php',
...
});
[/code]

Now I want to know, how many rows there are. The reply of the server contains iTotalRecords, but I don't get this number either by calling oTable.fnGetData().length or oTable.fnSettings().fnRecordsTotal().

[code]
console.log("Length: " + oTable.fnGetData().length);
console.log("Length: " + oTable.fnSettings().fnRecordsTotal());

// output:
Length: 0
Length: 0
[/code]

So, how do I get the number of rows using server side? Do I need to call the script again and manually evaluate the field iTotalRecords?

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Are you doing this after the data has been loaded (i.e. in fnInitCallback)? Remember that the Ajax request is async, so if you have your fnRecordsTotal() etc code right after initialising DataTables, it will be 0, since the data hasn't loaded yet.

    Allan
This discussion has been closed.