2016-04-15 25 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

相關問題