前端JS调用代码
$('#table_id').DataTable({ "language": { "sPRocessing": "处理中...", "sLengthMenu": "显示 _MENU_ 项结果", "sZeroRecords": "没有匹配结果", "sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项", "sInfoEmpty": "共0条记录", "sInfoFiltered": "", "sInfoPostFix": "", "sSearch": "", "sSearchPlaceholder":'请输入ID或者标题', "sUrl": "", "sEmptyTable": "表中数据为空", "sLoadingRecords": "载入中...", "sInfoThousands": ",", "oPaginate": { "sFirst": "首页", "sPrevious": "上页", "sNext": "下页", "sLast": "末页" }, }, bServerSide:true, Ajax:{ url:"{:U('signin/record')}", type:'post', dataSrc:'list' }, "columns":[{"width":"50px",'data':'userId','orderable':false}, {'width':'100px','data':'sign_time','orderable':false}, {'width':'60','data':'count'}, {'width':'50','data':'round'}, {'width':'150','data':'prize_status_label'}, ], "pageLength": 20, "lengthChange": false, "order": [[ 0, 'desc' ]], "dom": '<"toolbar">frtip', 'searching':false });红色标注部分为服务端ajax数据获取分页配置url:请求地址
type:请求类型
dataSrc:表示的是请求回来的数据对象中 哪个属性为列表数据 若值为list 则如 {recordsTotal:200,recordsFiltered:200,draw:'xxx','list:'[,,,,,,,,,,,,]}
服务端数据构造就如上述dataSrc配置数据格式即可
服务端返回的数据中 有一个draw属性 该值是为了防止xss攻击 前端传入什么 后端就返回什么
新闻热点
疑难解答