Heiko
Heiko

Reputation: 45

Datatables, the "infoEmpty"-message is displayed even though there are records

My datatable with ajax source will show the message which is declare in language.infoEmpty even though there are records in the table.

enter image description here

The function in a class to create the datatable:

createTable() {
const self = this;
let table = $('#' + this.getClassName()).DataTable({
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url": this.getUrl() + this.getClassName() + "/ajax-paging",
        "type": "POST"
    },
    "columnDefs": [
        {
            "name": 'id',
            "targets": [0],
            "visible": false,
            "searchable": false,
        },
        {
            "name": 'Aktiv',
            "targets": [2],
            "render": function (data, type, row) {
                if (type === 'display') {
                    let checkedvalue = '';
                    if (data) {
                        checkedvalue = 'checked="checked"';
                    }
                    return '<input style="margin-left: auto; margin-right: auto;" type="checkbox" class="form-control form-control_table" ' + checkedvalue + ' disabled>';
                }
                return data;
            },
            "searchable": false,

        },
        {
            "targets": [3],
            "render": function (data, type, row) {
                if (type === 'display') {
                    let ret = '<div style="float:right;" aria-label="benutzer actions"><img src="' + self.getUrl() + 'img/bootstrap-icons/search.svg" />';
                    return ret + '</div>';
                }
                return data;
            },
            "searchable": false,
        }
    ],
    "columns": [
        { data: self.idColName, name: "ID" },
        { data: ProjektKonstanten.COL_LOGINNAME, name: "Loginname" },
        { data: ProjektKonstanten.COL_AKTIV, name: "Aktiv" },
        { "orderable": false, data: self.idColName },
    ],
    "order": [1, 'asc'],
    "language": {
        "lengthMenu": '_MENU_ records per page'),
        "zeroRecords": 'No match',
        "info": 'Page _PAGE_ of _PAGES_',
        "infoEmpty": 'No user found',
        "infoFiltered": '(filtered from _MAX_ records)',
        "search": 'Search:',
        "paginate": {
            "first": "<img src='" + images.first + "'/>",
            "last": "<img src='" + images.last + "'/>",
            "next": "<img src='" + images.next + "'/>",
            "previous": "<img src='" + images.back + "'/>",
        }
    }
});
return $table;

}

Every suggestion/idea is welcome?

(I don't know what else to explain. But Stacktrace tells me that more code is written than explanations, so I am writing this text here so that Stacktrace let me do the post;))

Upvotes: 0

Views: 484

Answers (1)

Heiko
Heiko

Reputation: 45

After checking the JSON response, I saw that maxRowCount and recordFiltered parameters were 0. After they got the correct number, it worked.

Upvotes: 1

Related Questions