This article mainly introduces the jquery dataTable background loading data and paging example code, which has certain reference value. If you are interested, you can learn about it. I hope it can help everyone.
Use dataTable to load data in the background and paginate. There are many online versions, but many of them are unusable or not detailed. Here are the ones that have been verified.
Reference js file
Add a table tag, You can not use it, you can dynamically load
名称 | apiKey | secretKey | 创建时间 | Status | 操作 |
---|
Key JS code:
Backend code:
// 获取前端过来的参数,下面三个参数是 dataTable默认的,不要随便更改 Integer sEcho = Integer.valueOf(params.get("sEcho"));// 记录操作的次数 每次加1 Integer iDisplayStart = Integer.valueOf(params.get("iDisplayStart"));// 起始 Integer iDisplayLength = Integer.valueOf(params.get("iDisplayLength"));// 每页显示的size Mapmap = new HashMap (); try { // 查询数据,分页的话我这边使用的是 PageHelper,这边不介绍了 PagedResult list = pushEntityService.findByUserId( pushUser.getId(), iDisplayStart, iDisplayLength); // 为操作次数加1,必须这样做 int initEcho = sEcho + 1;
//返回参数也是固定的 map.put("sEcho", initEcho); map.put("iTotalRecords", list.getTotal());//数据总条数 map.put("iTotalDisplayRecords", list.getTotal());//显示的条数 map.put("aData", list.getDataList());//数据集合 } catch (Exception e) { e.printStackTrace(); } return map;
Related recommendations:
JQuery.dataTables table plug-in jumps to the specified page instance sharing
jquery DataTable front and backend dynamic paging implementation method sharing
About jQuery Datatable multiple query conditions custom submission event example sharing
The above is the detailed content of jquery dataTable loads data in the background and paging. For more information, please follow other related articles on the PHP Chinese website!