tabulator v5.1.0 新特性分页计数器及ajax pokeapi服务器分页,请求、响应参数修改示例

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Tabulator Example</title>
        <link href="css/tabulator.css" rel="stylesheet">
        <script type="text/javascript" src="js/tabulator.js"></script>
        <style>
            /*Horizontally center header and footer*/
            .tabulator-print-header, tabulator-print-footer{
                text-align:center;
            }
        </style>
    </head>
    <body>
        <div id="example-table"></div>
        <script type="text/javascript">
//Build Tabulator
            var table = new Tabulator("#example-table", {
                height: "311px",
                layout: "fitColumns",
                placeholder: "No Data Set",
                pagination: true, //enable pagination
                paginationMode: "remote", //enable remote pagination
                paginationSize: 5,
                paginationCounter: "rows", //display count of paginated rows in footer
                paginationInitialPage: 1,
                ajaxURL: "https://pokeapi.co/api/v2/pokemon", //set url for ajax request
                ajaxURLGenerator: function (url, config, params) {
                    console.log(params.page);
                    console.log(params.size);
                    var offset = (params.page - 1) * params.size;
                    var limit = params.size;
                    //https://pokeapi.co/api/v2/pokemon?offset=20&limit=20
                    return url + "?offset=" + offset + "&limit=" + limit; //encode parameters as a json object
                },
                ajaxResponse: function (url, params, response) {
                    console.log(response);
                    response['last_row'] = response['count'];
                    response['last_page'] = response['count'];
                    response['data'] = response['results'];
                    response.last_page = Math.ceil(response.count / table.getPageSize());
                    console.log("last_page:=" + response.last_page);
                    console.log("getPageSize=" + table.getPageSize());
                    console.log(response['last_page']);
                    return response;
                },

                columns: [
                    {title: "Pokemon", field: "name"},
                    {title: "URL", field: "url"},
                ],
            });
        </script>
    </body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值