How to call getJSON inside DataTable render function?

How to call getJSON inside DataTable render function?

hadriakihadriaki Posts: 1Questions: 1Answers: 0

I just started to learn dataTables.

Is it possible to use getJson() inside DataTable render function to render table data?

I'm getting undefined from console.log(category); at the moment.

Am I missing something here?

function loadHelpdeskTickets(id) {

$.getJSON(HELPDESKTICKETS_URL + "?filter[where][customerId]=" + id, function(data) {

var table = $('#helpdesk_table').DataTable({
    data: data,
    "order": [
        [1, "desc"]
    ],
    "processing": true,
    "bLengthChange": true,
    "bFilter": true,
    "bInfo": true,
    "paging": true,
    "columns": [{
            data: "id"
        },
        {
            data: "ticketOpen",
            render: function(data, type, row) {

                date = new Date(data);
                return date.toLocaleString("en-GB");
            }
        },
        {
            data: "category",
            render: function(data, type, row) {

                var category;

                $.getJSON(HELPDESKQUESTIONS_URL + "?filter[where][id]=" + data, function(data) {
                    $.each(data, function(key, val) {
                        console.log(val.type);
                        category = val.type;
                    });
                });

                console.log(category);
                return category;
            }
        },
        {
            data: "userId"
        },
        {
            data: "installerId"
        }

    ]
});

});

This discussion has been closed.