ajaxProgressiveLoad 可以在 Tabulator 中覆盖请求承诺吗

Can ajaxProgressiveLoad work with Overriding the Request Promise in Tabulator

它确实可以与 pagination: "remote" 一起使用,但**出于某种原因我们必须在 .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]));

更新了一张图片 enable ajaxUrl option

只要您以 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
    ]
}

并且您正确地将 page 参数传回您的服务器。

尽管查看 ajaxRequestFunc 它没有做内置 ajax 系统已经做的任何事情(特别是因为它在 v4.1 中的改进)所以我不确定为什么它是首先需要。

您需要确保 ajaxURL 选项有一个值,以便您的要调用的自定义加载程序