【发布时间】:2016-01-05 14:56:14
【问题描述】:
我想使用数据表实现服务器端分页,我可能有大约 200 条记录,我了解服务器端分页的工作原理,我们为每个链接单独发送 ajax 请求,现在当我们向服务器发送参数时,例如页码(绘制)页面开始,如果我想要每页 10 条记录,这是否意味着我们应该发送 20 条 ajax 请求,通过每次增加页码并处理来自服务器端的数据并每次返回 json 对象来发送 200 条记录?
这就是我实现它的方式除了语法之外我是如何实现它的?
$('#tableEM').DataTable( {
"sPaginationType": "full_numbers",
"processing": true,
"serverSide": true,
"sAjaxDataProp":"",
"columns":[{"keyword":"keyword","updated_date":"updated_date","action":"delete"}],
'paging': true,
"ajax": {
"url": "/rest/events/keywords/sereverPagination1",
type: "GET",
data:{
"iDisplayStart":i,
"iDisplayLength":10,
"draw": draw,
},
success: function (jsonEM)
{
console.log(jsonEM)
for(var i=0; i<=jsonEM.length; i++){
console.log(jsonEM[i])
console.log(i)
$('#topicContainer').append('<tr>'+
'<td>'+jsonEM[i].keyword+'</td>'+
'<td>'+jsonEM[i].updated_date+'</td>'+
'<td>'+jsonEM[i].action+'</td>'+
'</tr>')
}
}
}
} );
实施是否正确?请帮助。我正在使用弹簧作为后端
我的服务器端实现
@RequestMapping(value="/rest/events/keywords/sereverPagination1")
public List<EventMonitor> getResults(@RequestParam(value="iDisplayStart",required=true)int iDisplayStart,@RequestParam(value="iDisplayLength",required=true)int iDisplayLength){
ArrayList<EventMonitor> keywordList=(ArrayList<EventMonitor>) _eventMonitorDao.getTargetList(0);
ArrayList<EventMonitor> sublist= (ArrayList<EventMonitor>) keywordList.subList(iDisplayStart, iDisplayLength);
return sublist;
}
【问题讨论】:
标签: jquery json ajax pagination