datatable 表头和内容不对齐调整方法

70 篇文章 0 订阅
25 篇文章 1 订阅

1、在html页设置dom为固定列宽

2、datable属性设置不可自动调整 $(document).ready(function() { $('#cinfo').DataTable( { data:coustom_result, "language": { "searchPlaceholder": "搜索...", "sEmptyTable": "没有相关记录", "sInfo": "第 _START_ 到 _END_ 条记录,共 _TOTAL_ 条", "sInfoEmpty": "第 0 到 0 条记录,共 0 条", "paginate": { "first": "首页", "previous": "上页", "next": "下页", "last": "末页" }}, autoWidth:false, paging: true, 3、通过css的sty设置表头居中

3、通过 “columnDefs”、“fnRowCallback” 设置列宽及每列个性化对齐设置
$(document).ready(function() {
$(‘#netinfo’).DataTable( {
data:net_result,
“language”: {
“searchPlaceholder”: “搜索…”,
“sEmptyTable”: “没有相关记录”,
“sInfo”: “第 STARTEND 条记录,共 TOTAL 条”,
“sInfoEmpty”: “第 0 到 0 条记录,共 0 条”,
“paginate”: {
“first”: “首页”,
“previous”: “上页”,
“next”: “下页”,
“last”: “末页”
}},
autoWidth:false,
scrollX: true,
scrollY: ‘50vh’,
scrollCollapse: true,
paging: true,
“columnDefs”: [ { “width”: “5%”, “targets”: 0 },{ “width”: “5%”, “targets”: 1 },{ “width”: “5%”, “targets”: 2 },{ “width”: “10%”, “targets”: 3 }
,{ “width”: “10%”, “targets”: 4 },{ “width”: “10%”, “targets”: 4 }],
“fnRowCallback”: function (nRow, aData, iDisplayIndex) {//相当于给字段格式化
$(‘td:eq(0)’, nRow).attr(‘style’, ‘text-align:center;’);
$(‘td:eq(3)’, nRow).attr(‘style’, ‘text-align:left;’);
$(‘td:eq(4)’, nRow).attr(‘style’, ‘text-align:left;’);
$(‘td:eq(-2)’, nRow).attr(‘style’, ‘text-align:left;’);
$(‘td:eq(-1)’, nRow).attr(‘style’, ‘text-align:left;’);
},

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值