DataTables handling no data

DataTables handling no data

curtiscurtis Posts: 7Questions: 0Answers: 0
edited January 2010 in General
Hello,

I am using MVCContrib grid to create my table and I am wondering how to handle the situation when no data is returned and the grid show No Results. Any ideas? Right now it gives me a js error.

Replies

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Hi curtis,

    Just return an empty array (assuming you are using Ajax source data). If using server-side data, then it's basically the same, although of course iTotalRecords etc need to return 0 as well.

    Allan
  • curtiscurtis Posts: 7Questions: 0Answers: 0
    Allan,

    Thanks for the response. I am using MVCContrib Grid to build my table so when there is no data the table html is this:

    {code]There is no data available.[/code]

    Any ideas?

    Thanks
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Do you get a Javascript error or anything with that? I've just tried your table code and it works well in Safari 4.

    Allan
  • curtiscurtis Posts: 7Questions: 0Answers: 0
    The error is "sData is undefined" and the table being built my mvccontrib grid when no data is present:
    [code]There is no data available.[/code]

    Thanks
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    I'm a little confused. That table in and of itself is absolutely fine. There is no reason for it to fine. Are you replacing a current table with that one? Or indicating in some what that there might be more than one column (which is usually the cause of this error). Can you post an example please.

    Allan
  • cliftonitecliftonite Posts: 8Questions: 0Answers: 0
    I have a follow-up question on handling no data.

    I pass back an empty data array as instructed above, and that works great. But I am using fnInitComplete to do various other things when there *is* data.

    How can I know if the aaData array is empty from within an fnInitComplete callback so that I can make it stop doing its other stuff?

    Thanks!
  • cliftonitecliftonite Posts: 8Questions: 0Answers: 0
    I should mention that I'm using Ajax data:

    [code]"sAjaxSource": "../scripts/file.php"[/code]
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    You can use:

    [code]
    this.fnGetData().length === 0
    [/code]

    inside a callback function to find out if there is data available or not.

    Allan
  • cliftonitecliftonite Posts: 8Questions: 0Answers: 0
    Genius! Thanks!

    I really like this plugin, by the way. This is a fine piece of programming.
This discussion has been closed.