之前使用bootstrap table比较多,第一次使用tabulator,查了官方文档,一点一点debugger才整出来分页,记录一下。
使用的tabulator.js是 v3.5.1
html文件:
<div id="demoTable"></div>
js文件:
("#demoTable").tabulator({
pagination:"remote", //enable remote pagination
ajaxConfig: "POST", //ajax request type
ajaxURL:_ctx + '/view/getList', //set url for ajax request
ajaxResponse:function(url, params, response){
//url - the URL of the request
//params - the parameters passed with the request
//response - the JSON object returned in the body of the response.
var data = {list:response};
return data; //return the tableData property of a response json object
},
paginationSize:5, //optional paramter to request a certain number of rows per page
height : "100%",
layout : "fitColumns",
columnVertAlign : "bottom",
tooltips : true,
selectable : 1,
movableColumns : false,
columns : [
{title : "序号",field : "id",formatter : "rownum", width: 70, frozen : false,align : "center", headerSort : false,tooltipsHeader : false,tooltip : false},
{title : "名称 ",field : "name",sorter : "string",align : "center",editor : false,headerSort : false}
],
langs:{
"ch-ch":{
"pagination":{
"first":"<<",
// "first_title":"<",
"last":">>",
// "last_title":">",
"prev":"<",
// "prev_title":"<",
"next":">",
// "next_title":">",
},
},
},
});
$("#demoTable").tabulator("setLocale", "ch-ch");
java文件返回格式:
Map result = new HashMap();
result.put("data",列表数据);
result.put("last_page",总页数);
分页栏展示效果如下图所示:
总体上来说,样式有点丑,官方文档还是英文的,网上的资料也不多,没有bootstrap使用起来方便。