datatables分页配置

来源:互联网 发布:sql2008数据库删除语句 编辑:程序博客网 时间:2024/06/10 05:36

项目需要用到分页,查文档查了很久的说。

var table = $("#tableList").DataTable({                // "ajax": {                //     "url": "/knowledge/kbms/bulletin/find?pageNum=1",                //     "dataSrc": ""                // },                //"pageLength":20,                "sDom": 'rt<"row"<"col-sm-6 col-xs-5"i><"col-sm-6 col-xs-5"p>>',                "iDisplayLength": 20, //默认每页数量                //"bPaginate": true, //翻页功能                "bLengthChange": false, //改变每页显示数据数量                //"bFilter" : true, //过滤功能                "ordering": false,                'searching': false,                "bSort": false, //排序功能                //"bInfo" : true,//页脚信息                "processing": false,                "serverSide": true,                "sAjaxSource": "/kbms/QA/toBeAnswered",                "fnServerData": function(sSource, aoData, fnCallback) {                    //console.log(JSON.stringify(aoData));                    $.ajax({                        "type": "get",                        "url": sSource,                        "dataType": "json",                        "data": {                            'pageOffSet': aoData[3].value,                            // 'mid': mid                        }, // 以json格式传递                          "success": function(result) {                            //console.log(aoData);                            // var key = 'aaData';                            // resp[key] = resp['result'];                            // delete resp['result'];                            // console.log(resp);                            // fnCallback(resp);                            var returnData = {};                            //returnData.draw = data.draw; //这里直接自行返回了draw计数器,应该由后台返回                            returnData.recordsTotal = result.total; //返回数据全部记录                            returnData.recordsFiltered = result.total; //后台不实现过滤功能,每次查询均视作全部结果                            returnData.data = result.result; //返回的数据列表                            fnCallback(returnData);                        },                        error:function(data){                                                    }                    });                },                //"bPaginate" : true,                //"bProcessing": true//服务器端进行分页处理的意思                "oLanguage": lang,                "columns": [{                        "data": 'id',                        "title": "",                        'sClass': "text-center",                        "orderable": false,                        "visible": false,                        "searchable": false                    }, {                        // "data": "title",                        "title": "标题",                        "orderable": false,                        render: function(data, type, row) {                            return '<h4>' +                                '<a href="javascript:void(0)" class="text-dark"><strong>' + row.title + '</strong></a>' +                                '</h4>' +                                '<div class="text-muted"><a href="javascript:void(0)">' + row.creatorName + '</a>  <em>' + row.createtime + '</em></div>';                        }                    },{                        "data": 'name',                        "title": "模块目录",                        'sClass': "text-center",                        "orderable": false,                        "width": "150px"                    }, //data 数据 如果复杂逻辑可以写在回调fnRowCallback中否则可以直接返回aoData的属性                     {                        "data": 'replies',                        "title": "回复数",                        'sClass': "text-center",                        "orderable": false,                        "width": "100px"                    }, //data 数据 如果复杂逻辑可以写在回调fnRowCallback中否则可以直接返回aoData的属性                    {                        //"data": "creator",                        "title": "最后回复",                        'sClass': "text-center",                        "orderable": false,                        "width": "150px",                        render: function(data, type, row) {                            return '<a href="javascript:void(0)">' + row.finalReplyer + '</a><br><small>' + row.replytime + '</small>';                        }                    }                ],            });


原创粉丝点击