tabulator - ajaxProgressiveLoad 可以与覆盖制表符中的请求承诺一起使用吗
问题描述
它确实与pagination: "remote"
.net 一起使用,但 ** 出于某种原因,我们必须在 .net 中使用自定义 ajax 函数 ** 但不是ajaxURL
选项。
这是功能要求吗?提前感谢您的帮助。
以下是以下代码:
- 分页:带有自定义ajax的“远程”(有效)
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<link href="https://unpkg.com/tabulator-tables@4.1.2/dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@4.1.2/dist/js/tabulator.min.js"></script>
<script>
function queryRealm(url, config, params) {
return new Promise(function (resolve, reject) {
$.ajax({
url: 'data.php',
success: function(data){
resolve(JSON.parse(data));
},
error: function(error){
reject(error);
}
})
});
}
var table = new Tabulator("#example-table", {
ajaxRequestFunc: queryRealm,
pagination: 'remote',
columns: [{
title: "id",
field: "id",
},
{
title: "Name",
field: "name",
width: 200
}
],
height: "292px",
});
- ajaxProgressiveLoad:使用自定义 ajax 进行“滚动”(不起作用)
只需更改pagination: 'remote',
为ajaxProgressiveLoad: "scroll"
data.php 如下:
$data = [
["id"=>1, "name"=>"Billy Bob============"],
["id"=>2, "name"=>"Mary May"],
["id"=>3, "name"=>"Christine Lobowski"],
["id"=>4, "name"=>"Brendon Philips"],
["id"=>5, "name"=>"Margret Marmajuke"],
["id"=>6, "name"=>"Christine Lobowski"],
["id"=>7, "name"=>"Brendon Philips"],`enter code here`
["id"=>8, "name"=>"Margret Marmajuke"],
["id"=>9, "name"=>"Margret Marmajuke"],
];
echo(json_encode(["last_page"=>10, "data"=>$data]));
更新了图像 启用 ajaxUrl 选项
解决方案
只要您以 Tabulator 期望的分页形式格式化返回的数据,这应该可以工作:
{
"last_page":15, //the total number of available pages (this value must be greater than 0)
"data":[ // an array of row data objects
{"id":1, "name":"bob", "age":"23"} //example row data object
]
}
并且您正确地将页面参数传递回您的服务器。
虽然查看 ajaxRequestFunc 它并没有做任何内置 ajax 系统已经做的事情(特别是因为它在 v4.1 中的改进)所以我不确定为什么首先需要它。
您需要确保ajaxURL选项具有值才能调用您的自定义加载程序
推荐阅读
- python - 如何使用 for 循环访问 PyQt 中多个复选框的复选框文本?
- angular - Angular FormControl valueChanges 无法使用 mat-autocomplete
- unit-testing - 如何用 nix 测试共享库?
- python-3.x - 将 DataFrame 列转换为对列表
- python - 查找数据框中列的各种值之间的共同交集,其中值是数组/列表
- python-3.x - 如何计算 Detectron2 中的交集?
- javascript - 如何根据在反应 js 中触发的更改事件检查密码条件的多个验证
- jquery - 如果我删除 async:false,我的 ajax 调用将不再有效。但我不想使用 async:false
- php - 正则表达式日语单词无法逃脱
- java - 如何使用 PriorityQueue 进行排序
Java中的3值?