get a table with a message "emptyTable", if the aaData is an empty array

get a table with a message "emptyTable", if the aaData is an empty array

maryPomaryPo Posts: 11Questions: 4Answers: 0
edited May 2015 in Free community support

I am doing a ajax request to the server to get the data.When the array is empty, I want it to be displayed in a table row "emptyTable". I get message "emptyTable", if not used aoColumnDefs, but I'm getting warning "Requested unknown parameter ... " . I do not want to receive a warning!

 var searchTable = $('#baseTasks').dataTable({
        bFilter: false, bInfo: false, "bLengthChange": false,
        scrollY:"600px",scrollCollapse: true, paging:false,
        "aaData": tasks,
        "aoColumns": [
         { "mData": "name"
         },{"mData": "schoolClass"
         },{"mData": "complexity"
         },{"mData": "author"
    }]
});

if I use aoColumnDefs, I do not get warning, but I get an empty table without message "emptyTable".

"aoColumnDefs": [
           {
                "mData": null,
               "sDefaultContent": null,
                "aTargets": [ -1 ]
            }],

How do I get a table with a message "emptyTable", if the aaData is an empty array?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    That error suggests that aaData is not empty. Perhaps it has an inner empty array that should be removed? Can you link to the page showing the issue please.

    Allan

  • maryPomaryPo Posts: 11Questions: 4Answers: 0
    edited May 2015

    Thank you for your answer, Allan, I can not give a link to the page, as the development is local. But I could recreate example here http://jsfiddle.net/bbubdp37/. By clicking on the "archive", there is bug described by me.

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Answer ✓

    I see - thanks for the test case. Why are you attempting to add a row to an empty table, when you want an empty table? :-)

    Just use fnClearTable and then don't add anything: http://jsfiddle.net/bbubdp37/1/

    Allan

  • maryPomaryPo Posts: 11Questions: 4Answers: 0
    edited May 2015

    I attempting to add a row to an empty table for an example. Since when clicked, in reality, a ajax request is made, and the data array may be empty or not empty. And I simply add the response data in the table.

    Thanks for your reply, now I will add a check if the data is empty, do not add anything to the table.

    Too bad it does not come to mind immediately. :-)

This discussion has been closed.