Search code examples
jqueryajaxhtmldatatable

DataTables warning: table id=datatable - Requested unknown parameter '0' for row 0, column 0


I was trying to initialize a datatable with a ajax response. But I got error message like this.

DataTables warning: table id=datatable - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

This is my datatable initialization.

table = $('#datatable').DataTable({
    "ajax": {
        type: 'POST',
        url: 'bridgeHandler.php',
        data: {action: 'getAllCategories'},
        'columns': [
            {"data": "name"},
            {"data": "description"},
            {"data": null,
                "render": function (data, type, row) {
                    return "";
                }
            },
        ]
    },
    "initComplete": function (settings, json) {
        // Apply the search
        table.columns().every(function () {
            var that = this;
            $('#datatable', this.footer()).on('keyup change', function () {
                if (that.search() !== this.value) {
                    that
                            .search(this.value)
                            .draw();
                }
            });
        });
    },
    destroy: true,
    ordering: false
});

And this is my JSON response

{"data":[{"id":"3","name":"fgdgfdfg","description":"gfgdfgfdg"}]}

This is that error message:


Solution

  • Response from Ajax has not matched the column size in some cases. It was the issue.