With no data, how do I prevent an error when it expects something?

With no data, how do I prevent an error when it expects something?

TeonnynTeonnyn Posts: 10Questions: 1Answers: 0

I've got a working setup, however tables that don't have any data generally receive "{"data" : [] }" in response. This causes an output error, even though nothing is actually wrong. The output structure is used for all of my tables, so the number of columns could vary wildly, as well as naming. With these in mind, how can I modify the output so that DataTables will allow for no data?

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    DataTables should not throw an error if it receives an empty array. Can you link to a test page, showing the issue, as per the forum rules, so we can help to debug this please.

    Allan

  • TeonnynTeonnyn Posts: 10Questions: 1Answers: 0
    edited October 2015

    I figured it out in a sense, by creating some bogus data that just reads "empty: empty" when it finds nothing, and assigning defaults - no more errors at the moment!

    While that may not be ideal, I'm using the basic code only at the moment

      $('#ArticleTable').DataTable({
              ajax: "Article/json", 
             "columns": [
    
            { data: "id", "defaultContent": "0" },
            { data: "title", "defaultContent": "None" },
            { data: "status", "defaultContent": "None" },
            { data: "author", "defaultContent": "None" }
        ]
    });
    
This discussion has been closed.