如何居中对齐数据表标题 [英] How to center align datatables header

查看:134
本文介绍了如何居中对齐数据表标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是数据表的新手.当我制作表格标题时,它总是左对齐. 如何将标题设置为居中对齐? 我已经阅读了datatables.net/manual/styling/classes和datatables.net/reference/option/columns.className,但仍然不知道如何实现它.

I'm new to datatables. When I make table header, it's always left align. How can I set the header to center align? I've read datatables.net/manual/styling/classes and datatables.net/reference/option/columns.className but still don't know how to implement it.

$('.table').DataTable({
  "paging": true,
  "lengthChange": true,
  "searching": true,
  "ordering": true,
  "info": true,
  "language": {
    "url": "http://cdn.datatables.net/plug-ins/1.10.9/i18n/Indonesian.json"
  }
  "columnDefs": {
    {
      className: "dt-head-center"
    }
  }
});

推荐答案

在指定了类之后,您可能已经忘记了,您需要在CSS中添加以下内容:

You might have forgotten after specifying the class, you need to add the following in CSS:

.dt-head-center {text-align: center;}

此外,如果尚未将类添加到表的<th>中,请尝试为通用内容添加以下CSS:

Also, if the class has not been added to the <th> of the table, try adding the below CSS for generic stuff:

thead, th {text-align: center;}

/* OR */

.table thead,
.table th {text-align: center;}

要使其特定于特定表,您可以为表指定一个id="tableID",然后在CSS中可以执行以下操作:

To make it specific to a particular table, you can give the table an id="tableID" and then in the CSS, you can do:

#tableID thead,
#tableID th {text-align: center;}

这篇关于如何居中对齐数据表标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆