Do you have better way to know if server side table is empty?

Do you have better way to know if server side table is empty?

SimonshengSimonsheng Posts: 10Questions: 0Answers: 0
edited July 2012 in General
I am checking server side table if it is empty or not by the div that id is 'tableName_info'(under the table bottom, and show entry's number )
I get it's text that is "Showing number to number of number entries" and split them by space into array, then I need the number after "of"
the code is below. but it is urgily, I don't like this way! does datatabe has some thing I can read or occur so I can check if it is empty or not?
[code]if($('#tableName_info').text().split(" ")[5]!=0)
{
do something for table has record
}
else
{
do something for empty table
}[/code]
and I know oSettings.fnRecordsTotal() can return the Record's number , but I don't know how to use it in my webpage.
Can anyone demo me?
Thank you very much.

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    I'd recommended using the fnPagingInfo ( http://datatables.net/plug-ins/api#fnPagingInfo ) plug-in.

    Allan
  • SimonshengSimonsheng Posts: 10Questions: 0Answers: 0
    edited July 2012
    If I read the attribute like iPage in call back function fnDrawCallback, it is working well. but If I read them in my code by this way[code]$('#tableName').dataTable().fnPagingInfo().iTotal[/code] they are always zero. I know this is js problem, but how to fix it?
    More Information:
    I use getread to create datatable first, later when I need the iTotal, I am tring use the code to read iTotal.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    In fnDrawCallback use:

    [code]
    this.fnPagingInfo().iTotal
    [/code]

    If that doesn't work, can you give us a link to the page please?

    Allan
  • tlgtrntlgtrn Posts: 1Questions: 0Answers: 0
    I am using this code

    [code]
    "fnDrawCallback": function (oSettings) {
    if (oSettings._iDisplayEnd == 0) {
    ... // your code here
    }
    }
    [/code]
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    _iDisplayEnd is an internal variable which is liable to change in future (unlikely, but it is possible). I'd suggest you use the API method suggested above. Thinking I might include it in DataTables 1.10 anyway...

    Allan
This discussion has been closed.