jquery - 数据表,即使有记录也会显示“infoEmpty”消息
问题描述
我的带有 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 让我做帖子;))
解决方案
检查 JSON 响应后,我看到 maxRowCount 和 recordFiltered 参数为 0。在他们得到正确的数字后,它就起作用了。
推荐阅读
- java - Junit 5 @MockBean 中的 NullPointerException
- python - Pandas - 将每个可重复类的 ID 分组并将它们放在列中的列表中
- django - Django 数据表加载时间过长
- css - 在 ionic 5 中,Scss 文件未编译为 css 文件
- python - pandas: assign value based on equivalent value in another row with lookup
- python - PyVISA 和 PyMeasure 的问题 - 如何解决?
- react-native - 如何在 React Native 中自动缩放图像?
- r - 如何将我的特定位置分配给他们的社区?
- python - col - Python中唯一标签的绘图线
- sql-server - 可以创建用户但不能更改它?