1、引用在线的CDN文件或者下载后在本地引用
2、由于datatables实在jquery基础上开发的插件,在引入datatables相关的JS和css,需要先引入jquery文件
3.两个文件分别是:
jquery.dataTables.min.jsjquery.dataTables.min.css1.通过$()选定要操作的表格例如
$(document).ready(function(){$('#myTable').DataTable();});
(1).在$('#myTable').DataTable({...});里面做简单的基础配置:
language: {"processing": "处理中...","lengthMenu": "显示 _MENU_ 项结果","zeroRecords": "没有匹配结果","info": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项","infoEmpty": "显示第 0 至 0 项结果,共 0 项","infoFiltered": "(由 _MAX_ 项结果过滤)","infoPostFix": "","search": "搜索:","searchPlaceholder": "搜索...","url": "","emptyTable": "表中数据为空","loadingRecords": "载入中...","infoThousands": ",","paginate": {"first": "首页","previous": "上页","next": "下页","last": "末页"},"aria": {"paginate": {"first": "首页","previous": "上页","next": "下页","last": "末页"},"sortAscending": "以升序排列此列","sortDescending": "以降序排列此列"},"thousands": "."}
"stateSave": true,
"stateDuration": -1,name(字段名字),render(处理当前数据)
columns: [{data: 'id'}, {data: 'name',orderable: false}, {data: 'email',orderable: false}, {data: 'title'}, {data: "status",render: function(data, type, row) {return data > 0 ? "开启" : "禁用";}}],
"columnDefs": [{"targets": 5,//自定义的列(数字标识第几列的索引,从0开始)"render": function(data, type, row) {return '返回处理过的数据';}}],
data字段即可data字段;serverSide:true;来开启后端配置1.接收参数字段:
draw:前端求情唯一标识start:当前页数据的条目起始数length:页面的显示的条目数order:需要排序的信息:column:需要排序的列的索引,一般通过索引(前端的列信息)获取需要排序的字段dir:排序的规则:默认asc升序,desc降序search:搜索的的值
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号