【问题标题】:Datatables, the "infoEmpty"-message is displayed even though there are records数据表,即使有记录也会显示“infoEmpty”消息
【发布时间】:2021-08-30 12:06:13
【问题描述】:

即使表中有记录,我的带有 ajax 源的数据表也会显示在 language.infoEmpty 中声明的消息。

类中创建数据表的函数:

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;

}

欢迎任何建议/想法?

(我不知道还有什么要解释的。但是 Stacktrace 告诉我写的代码比解释多,所以我在这里写这篇文章是为了让 Stacktrace 让我发帖;))

【问题讨论】:

  • 一些问题:(1)“...即使表中有记录” - 你怎么知道?你能告诉我们吗? (2) 来自 Ajax URL 的 JSON 响应的结构是什么?你能告诉我们(作为 JSON 文本)吗? (3) HTML表格是如何定义的?你能告诉我们实际的 HTML 吗?
  • (1) 查看图片。灰色的是一排。感谢 JSON 响应的提示。 maxRowCount 和 recordFiltered 参数为 0。
  • 啊 - 我明白了 - 我的错误。现在问题解决了,我想。欢迎您answer your own question。这可能会帮助未来的访问者解决这个问题。

标签: jquery ajax datatables


【解决方案1】:

查看 JSON 响应后,我看到 maxRowCount 和 recordFiltered 参数为 0。 在他们得到正确的号码后,它就起作用了。

【讨论】:

    猜你喜欢
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 2018-08-14
    • 2023-03-15
    • 1970-01-01
    • 2012-07-12
    相关资源
    最近更新 更多