[Answered ]-Django – jQuery datatables stuck on loading

2👍

The library is looking for the data to be in the property of aaData of the response from the server. Since the server is returning a list of objects, it’s says it’s undefined when it tries to access it.

You can’t be using an empty string for sAjaxDataProp. You can read up more on what you should be returning from the server here: http://legacy.datatables.net/usage/server-side.

Change your jQuery part to:

$(document).ready(function () {
    $('#rfctable').dataTable({
        "sAjaxDataProp": 'data',
        "ajax": 'http://127.0.0.1:8000/api/',
        "columns": [
            { "fields": "rfc_number"},
            { "fields": "rfc_title"},
            { "fields": "rfc_question"},
        ]

    });
});

Change the response from the server to be:

{"data": [
    {
        "pk": 1,
        "model": "rfc.rfcdocument",
        "fields": {
            "rfc_title": "123123123123",
            "rfc_answer_reviewed_by": 1,
            "rfc_required_fcd": true,
            "rfc_drawing_detail_number": "123",
            "rfc_required_sketch": true,
            "rfc_answer_authorized_by": 1,
            "rfc_issued_by": 1,
            "rfc_answer_issued_date": null,
            "rfc_specification_section": "34-5",
            "rfc_answered_date_architect": null,
            "rfc_question": "Salam baba?",
            "rfc_issued_date": null,
            "rfc_answer": "salama back!",
            "rfc_project": 1,
            "rfc_required_fls_review": true,
            "rfc_drawing_page_number": "54",
            "rfc_issued_to": 1
        }
    }
]}

You should also be returning iTotalRecords, iTotalDisplayRecords, and sEcho in the response.

Leave a comment