Scroller doesn't show results after processing json

Scroller doesn't show results after processing json

AbdizrielAbdizriel Posts: 3Questions: 1Answers: 0

Hello,

I've got following datatable code:

var table = $('#table').DataTable({
        responsive: true,
        colReorder: true,
            ajax: {
                     url: '/some/api',
            dataSrc: function ( json ) {
                for ( var i=0; i<json.data.length ; i++ ) {
                    for(var j=0; j <json.data[i].length; j++){
                        if(json.data[i][j] == "") json.data[i][j] = "NA"
                    }
                }
                return json;
            }
        }
        scrollY: 400,
        deferRender: true,
        scroller: true,
        "order": [[0, "desc"]],
        columns: [
            {data: 0},
            {data: 1},
            {data: 2},
            {data: 3}
        ]
    });

When I add that part:

dataSrc: function ( json ) {
                for ( var i=0; i<json.data.length ; i++ ) {
                    for(var j=0; j <json.data[i].length; j++){
                        if(json.data[i][j] == "") json.data[i][j] = "NA"
                    }
                }
                return json;
            }

Datatable doesn't have any records, but when i don't add that it show results but they're not processed.
What's wrong with that code?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,051 Site admin
    Answer ✓

    Can you link to a test case showing the issue please.

    I suspect you need to return json.data since the ajax.dataSrc function expects the data array to be returned.

    Allan

  • AbdizrielAbdizriel Posts: 3Questions: 1Answers: 0

    Yes! That was the issue :)
    Thanks!

This discussion has been closed.