gpt4 book ai didi

jquery - 为什么在 DataTable() 上调用 ajax.reload() 返回未定义?

转载 作者:行者123 更新时间:2023-12-01 04:00:48 25 4
gpt4 key购买 nike

到目前为止我已经做到了这一点。完全加载后,表格完美显示。但是当我添加 t.ajax.reload() 时,它显示 TypeError: t.ajax is undefined

$.fn.dataTableExt.oApi.fnPagingInfo = function(oSettings)
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
"iTotalPages": Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
};
};

var t = $("#mytable").dataTable({
initComplete: function() {
var api = this.api();
$('#mytable_filter input')
.off('.DT')
.on('keyup.DT', function(e) {
if (e.keyCode == 13) {
api.search(this.value).draw();
}
});
},
oLanguage: {
sProcessing: "loading..."
},
processing: true,
serverSide: true,
ajax: {"url": "data/json", "type": "POST"},
columns: [
{
"data": "id",
"orderable": false
},
{"data": "nama"},
{"data": "stok"},
{"data": "satuan"},
{
"data" : "action",
"orderable": false,
"className" : "text-center"
}
],
order: [[0, 'desc']],
rowCallback: function(row, data, iDisplayIndex) {
var info = this.fnPagingInfo();
var page = info.iPage;
var length = info.iLength;
var index = page * length + (iDisplayIndex + 1);
$('td:eq(0)', row).html(index);
}
});

setInterval( function () {
t.ajax.reload();
}, 3000 );

如有任何建议,我们将不胜感激。提前致谢!

最佳答案

来自DataTables documentation

It is important to note the difference between $( selector ).DataTable() and $( selector ).dataTable(). The former returns a DataTables API instance, while the latter returns a jQuery object. An api() method is added to the jQuery object so you can easily access the API, but the jQuery object can be useful for manipulating the table node, as you would with any other jQuery instance (such as using addClass(), etc.).

因此:

var t = $("#mytable").DataTable({...}); // capital D

关于jquery - 为什么在 DataTable() 上调用 ajax.reload() 返回未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44642243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com