spring下DataTable伺服器分頁

來源:互聯網
上載者:User

標籤:操作   play   方法   tar   function   back   width   style   array   

JSP中body內容:

<table class="table table-border table-bordered table-bg table-hover table-sort">        <thead>            <tr class="text-c">                <th width="80">ID</th>                <th width="100">類型</th>                <th>內容</th>                <th width="17%">使用者名稱</th>                <th width="120">用戶端IP</th>                <th width="120">時間</th>                <!-- <th width="70">操作</th> -->            </tr>        </thead>    </table>

 

JS內容:

    $(‘.table-sort‘).dataTable({            "bProcessing": false, // 是否顯示取資料時的那個等待提示            "bServerSide": true,//這個用來指明是通過服務端來取資料            "bPaginate": true,  //是否顯示分頁            "sAjaxSource": "${cxtPath}/globalLog/getList",//這個是請求的地址            "fnServerData": retrieveData, // 擷取資料的處理函數            "aoColumns": [                          { "mData": "id"},                          { "mData": "type"},                          { "mData": "info"},                          { "mData": "userName"},                          { "mData": "ip"},                          { "mData": "time"}                      ] //對應表格中的每一列                });    function retrieveData( sSource111,aoData111, fnCallback111) {        $.ajax({            url : sSource111,//這個就是請求地址對應sAjaxSource            data : {"aoData":JSON.stringify(aoData111)},//這個是把datatable的一些基本資料傳給後台,比如起始位置,每頁顯示的行數            type : ‘post‘,            dataType : ‘json‘,            async : false,            success : function(result) {                fnCallback111(result);//把返回的資料傳給這個方法就可以了,datatable會自動綁定資料的            },            error : function(msg) {            }        });    }

 

java代碼:

 1 @RequestMapping(value = "/getList") 2     @ResponseBody 3     public String getList(@RequestParam String aoData) { 4         JSONArray jsonarray=(JSONArray) JSONArray.parse(aoData); 5  6         String sEcho = null; 7         int iDisplayStart = 0; // 起始索引 8         int iDisplayLength = 10; // 每頁顯示的行數 9 10         for (int i = 0; i < jsonarray.size(); i++) {11             JSONObject obj = (JSONObject) jsonarray.get(i);12             if (obj.get("name").equals("sEcho"))13                 sEcho = obj.get("value").toString();14 15             if (obj.get("name").equals("iDisplayStart"))16                 iDisplayStart =Integer.parseInt(obj.get("value").toString());17 18             if (obj.get("name").equals("iDisplayLength"))19                 iDisplayLength = Integer.parseInt(obj.get("value").toString());20         }21         22         23                 JSONObject getObj = new JSONObject();24                 getObj.put("sEcho", sEcho);// DataTable前台必須要的25                 getObj.put("iTotalRecords",globalLogService.getCount());//實際的行數,調用查詢總記錄數的方法26                 getObj.put("iTotalDisplayRecords",globalLogService.getCount());//顯示的行數,這個要和上面寫的一樣27                 28                 getObj.put("aaData", globalLogService.getList(iDisplayStart, iDisplayLength));//把查到資料裝入aaData,要以JSON格式返回29                 return JSONObject.toJSONString(getObj);30     }

 :

spring下DataTable伺服器分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.