博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
datatables ajax异步分页
阅读量:4882 次
发布时间:2019-06-11

本文共 5775 字,大约阅读时间需要 19 分钟。

$('#sample_1').dataTable({                 "sAjaxSource": "../table/data",//                 "bProcessing": true,                 "bServerSide": true,                 "fnServerData": function ( sSource, aoData, fnCallback ) {                     console.log(111)                     console.log(JSON.stringify(aoData));                     $.ajax( {                     "dataType": 'json',                     "type": "POST",                     "url": sSource,                     "data": aoData,                     "success": fnCallback                     } );                 },                 "bDeferRender": true,// 是否启用延迟加载:当你使用AJAX数据源时,可以提升速度。默认值:False//                        "aaData": [//                            /* Reduced data set *///                            [ "Trident", "Internet Explorer 4.0", "Win 95+", 4, "X" ],//                            [ "Trident", "Internet Explorer 5.0", "Win 95+", 5, "C" ],//                            [ "Trident", "Internet Explorer 5.5", "Win 95+", 5.5, "A" ],//                            [ "Trident", "Internet Explorer 6.0", "Win 98+", 6, "A" ],//                            [ "Trident", "Internet Explorer 7.0", "Win XP SP2+", 7, "A" ],//                            [ "Gecko", "Firefox 1.5", "Win 98+ / OSX.2+", 1.8, "A" ],//                            [ "Gecko", "Firefox 2", "Win 98+ / OSX.2+", 1.8, "A" ],//                            [ "Gecko", "Firefox 3", "Win 2k+ / OSX.3+", 1.9, "A" ],//                            [ "Webkit", "Safari 1.2", "OSX.3", 125.5, "A" ],//                            [ "Webkit", "Safari 1.3", "OSX.3", 312.8, "A" ],//                            [ "Webkit", "Safari 2.0", "OSX.4+", 419.3, "A" ],//                            [ "Webkit", "Safari 3.0", "OSX.4+", 522.1, "A" ]//                        ],                "aoColumns": [                  { "bSortable": false },                  null,                  { "bSortable": false },                  null,                  { "bSortable": false },                  { "bSortable": false }                ],                "aLengthMenu": [                    [5, 15, 20, -1],                    [5, 15, 20, "All"] // change per page values here                ],                // set the initial value                "iDisplayLength": 5,                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",                "sPaginationType": "bootstrap",                "oLanguage": {                    "sLengthMenu": "_MENU_ records per page",                    "oPaginate": {                        "sPrevious": "Prev",                        "sNext": "Next"                    }                },                "aoColumnDefs": [{                        'bSortable': false,                        'aTargets': [0]                    }                ]            });

 

 

@RequestMapping("/data")    @ResponseBody    public PageResult data(HttpServletRequest request,@ModelAttribute PageRequest pageRequest){//                PageResult result = new PageResult();        JSONArray aaData = new JSONArray();        for (int i = pageRequest.getiDisplayStart(); i < pageRequest.getiDisplayStart()+pageRequest.getiDisplayLength(); i++) {            JSONArray row = new JSONArray();            row.add("a"+i);            row.add("b"+i);            row.add("c"+i);            row.add("d"+i);            row.add("e"+i);            row.add("f"+i);            aaData.add(row);        }        result.setAaData(aaData);        result.setSEcho(pageRequest.getsEcho()+1);        result.setITotalRecords(30);        result.setITotalDisplayRecords(30);        return result;    }
import com.alibaba.fastjson.JSONArray;public class PageResult {        private Integer sEcho;//    private Integer iTotalRecords;//实际的行数    private Integer iTotalDisplayRecords;//过滤之后,实际的行数。    private String sColumns;//可选,以逗号分隔的列名,;    private JSONArray aaData;        public PageResult() {        super();    }    public Integer getSEcho() {        return sEcho;    }    public void setSEcho(Integer sEcho) {        this.sEcho = sEcho;    }    public Integer getITotalRecords() {        return iTotalRecords;    }    public void setITotalRecords(Integer iTotalRecords) {        this.iTotalRecords = iTotalRecords;    }    public Integer getITotalDisplayRecords() {        return iTotalDisplayRecords;    }    public void setITotalDisplayRecords(Integer iTotalDisplayRecords) {        this.iTotalDisplayRecords = iTotalDisplayRecords;    }    public String getSColumns() {        return sColumns;    }    public void setSColumns(String sColumns) {        this.sColumns = sColumns;    }    public JSONArray getAaData() {        return aaData;    }    public void setAaData(JSONArray aaData) {        this.aaData = aaData;    }            }
public class PageRequest {        private int sEcho;//页数    private int iColumns;//    private String sColumns;    private int iDisplayStart;//开始行数    private int iDisplayLength;//结束行数        public int getsEcho() {        return sEcho;    }    public void setsEcho(int sEcho) {        this.sEcho = sEcho;    }    public int getiColumns() {        return iColumns;    }    public void setiColumns(int iColumns) {        this.iColumns = iColumns;    }    public String getsColumns() {        return sColumns;    }    public void setsColumns(String sColumns) {        this.sColumns = sColumns;    }    public int getiDisplayStart() {        return iDisplayStart;    }    public void setiDisplayStart(int iDisplayStart) {        this.iDisplayStart = iDisplayStart;    }    public int getiDisplayLength() {        return iDisplayLength;    }    public void setiDisplayLength(int iDisplayLength) {        this.iDisplayLength = iDisplayLength;    }        }

 

转载于:https://www.cnblogs.com/chyg/p/6379186.html

你可能感兴趣的文章
unity点选构建Mesh并保存OBJ
查看>>
python kmeans实战 - 单机一层聚类(小玩具哦),下次再弄个分布式多次聚类
查看>>
Java主要有那几种文件类型?各自的作用是什么?
查看>>
我的第一个python web开发框架(29)——定制ORM(五)
查看>>
2017.11.18 手把手教你学51单片机-点亮LED
查看>>
xml的创建与解析
查看>>
grep不区分大小写查找字符串方法
查看>>
linux系统灵活运用灯[android课程3]
查看>>
Android 通用Dialog中设置RecyclerView
查看>>
利用 Android Studio 和 Gradle 打包多版本APK
查看>>
Android 自定义标题栏
查看>>
Android 如何把一个 RelativeLayout或ImageView背景设为透明
查看>>
tomcat优化方向
查看>>
http
查看>>
8-1-组队赛
查看>>
codility: CountTriangles
查看>>
赛斯说
查看>>
python 中的pipe
查看>>
(SQL Analyzer services)定义链接维度
查看>>
squid
查看>>