$('#example11').dataTable({
"bFilter": false,//去掉搜索框
//"bAutoWidth": true, //自适应宽度
"sPaginationType" : "full_numbers",
"bDestroy" : true,
"bProcessing" : true,
"bServerSide" : true,
"sAjaxDataProp" : "aData",//是服务器分页的标志,必须有
"sAjaxSource" : "${pageContext.request.contextPath}/datatable/datainfo",//通过ajax实现分页的url路径。
"aoColumns" : [ {
"mDataProp" : "id",
}, {
"mDataProp" : "name",
}, {
"mDataProp" : "telephone",
}, {
"mDataProp" : "email",
}, ],
// 如果不知是简单的数据显示,需要复杂的要求时,通过以下方法来实现动态js插入。
//不知道有没有更好的方法。
"aoColumnDefs":[{"aTargets":[1],"mRender":function(){
return "1441"}
}],
"bAutoWidth": true, //自适应宽度
"sPaginationType" : "full_numbers",
"oLanguage" : {
"sProcessing" : "正在加载中......",
"sLengthMenu" : "每页显示 _MENU_ 条记录",
"sZeroRecords" : "正在加载中......",
"sEmptyTable" : "表中无数据存在!",
"sInfo" : "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
"sInfoEmpty" : "显示0到0条记录",
"sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
"sSearch" : "搜索",
"oPaginate" : {
"sFirst" : "首页",
"sPrevious" : "上一页",
"sNext" : "下一页",
"sLast" : "末页"
}
}
});
});
接下来是后台,涉及到json的地方也很麻烦
@ResponseBody
@RequestMapping("datainfo")
public Map datainfo(HttpServletRequest request,Model model,HttpServletResponse response) throws IOException{
JSONObject jsonobj =new JSONObject();
jsonobj.put("aData", DatatableDao.userList);
Map map = new HashMap();
map.put("sEcho", request.getParameter("sEcho"));
map.put("iTotalRecords", 30);
map.put("iTotalDisplayRecords", 30);
map.put("aData", DatatableDao.userList);
model.addAttribute("aData",DatatableDao.userList);
System.out.println(jsonobj.toJSONString());
return map;
}
text/html;charset=UTF-8
com.fasterxml.jackson.core
jackson-core
2.7.1
junit
junit
3.8.1
test
com.fasterxml.jackson.core
jackson-databind
2.7.1-1
com.fasterxml.jackson.core
jackson-annotations
2.7.1
org.json
json
20151123
com.alibaba
fastjson
1.2.7