服务器端分页数据表

时间:2015-10-08 06:25:30

标签: jquery json ajax pagination

我想使用数据表实现服务器端分页,我可能有大约200条记录,我理解服务器端分页如何工作,我们为每个链接分别发送ajax请求,现在我们向服务器发送参数如页码(绘制)页面开始,如果我想要每页10条记录,是否意味着我们应该发送20条ajax请求,每次增加页面数量200条记录并从服务器端处理数据并每次返回json对象?

这是我实现它的方式除了syntaxt这是我实现它的方式吗?

$('#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;
}

0 个答案:

没有答案
相关问题