What should json data look like for 'No Records"?

What should json data look like for 'No Records"?

kpgracikpgraci Posts: 4Questions: 2Answers: 1

If my server side API returns 0 records the table shows 'Processing..."

I tried to return the following with the same result:

{"data":null,"draw":1,"recordsFiltered":0,"recordsTotal":0}

and

{"data":[null],"draw":1,"recordsFiltered":0,"recordsTotal":0}

How does DataTables recognize that there are no results?

thx
kpg

This question has accepted answers - jump to:

Answers

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30
    Answer ✓

    Your response should be as shown below.

    {"data":[],"draw":1,"recordsFiltered":0,"recordsTotal":0}
    

    See this example for demonstration.


    See more articles about jQuery DataTables on gyrocode.com.

  • allanallan Posts: 57,265Questions: 1Answers: 9,121 Site admin
    Answer ✓

    Yes - it should just be an empty array. The next major version will allow null as well, but an empty array is semantically the correct thing to do (i.e. no records).

    Allan

  • kpgracikpgraci Posts: 4Questions: 2Answers: 1

    In my case I can not return an empty array, it's null or something, so this is a workaround that works nicely: (added to the ajax object)

                dataSrc: function (json) {
                    if (!json.data) {
                        return [];
                    } else {
                        return json.data;
                    }
    
This discussion has been closed.