首页 > 解决方案 > ajaxProgressiveLoad 可以与覆盖制表符中的请求承诺一起使用吗

问题描述

它确实与pagination: "remote".net 一起使用,但 ** 出于某种原因,我们必须在 .net 中使用自定义 ajax 函数 ** 但不是ajaxURL选项。

这是功能要求吗?提前感谢您的帮助。


以下是以下代码:

<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",
    });


只需更改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

解决方案


只要您以 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选项具有值才能调用您的自定义加载程序


推荐阅读