2016-04-15 26 views
2

我正在使用数据表,并且想知道是否有一个选项可以使标题换行。datatables - 使第一个标题单元格包装单词

我使用手机模式

enter image description here

问题是,一些javascript设置表头单元的宽度至像素的修复数量。

,所以我想:

fees 
covered 

name 
shown 


amount 
shown 
在头

编辑

:与加入<br/>标签的问题是,列的宽度留完全一样,但我他们想变小,宽度更小,在这里看到:

enter image description here

回答

4

使用锂NE表头打破<br>

<table id="example" class="display" cellspacing="0" width="100%"> 
    <thead> 
     <tr> 
      <th>fees<br>covered</th> 
      <th>name<br>shown</th> 
      <th>amount<br>shown</th> 
     </tr> 
    </thead> 
</table> 

代码和演示见this jsFiddle

+0

我为我的问题添加了编辑。主要目标是列不那么宽。当添加br时,宽度保持完全相同,即在这种情况下为81px。你知道一种让em更小的方法吗? – Toskan

+0

@Toskan,每列使用['columns.width'](https://datatables.net/reference/option/columns.width)。另见['autoWidth'](https://datatables.net/reference/option/autoWidth)选项。 –

0

根据你的表是如何初始化,那么你可以一个columns定义中使用title关键的适应:

"title": "Your Title".split(" ").join("<br/>"), // Your<br/>Title 

Example JSFiddle here

+0

这与@ Gyrocode.com的答案基本相同 – annoyingmouse

相关问题