table().header.structure()
自:DataTables 2.0 起
取得表格標頭結構的 Javascript 表示形式。
描述
此方法提供取得表格標頭 HTML 結構的 Javascript 原生表示形式的能力。 它允許複雜的標頭(即具有 colspan
和 rowspan
屬性的儲存格)和多列標頭。
傳回的資料結構具有一個頂層陣列,其中每個標頭列都有一個條目。每個列條目是一個物件陣列或一個 null 值。物件結構用於描述表格儲存格,並具有以下屬性
colspan
- 儲存格跨越的欄數cell
- 儲存格的 HTML 元素 (th
或td
)rowspan
- 儲存格跨越的列數title
- 儲存格的標題文字。
物件位置中的 null
值表示由於先前儲存格的 rowspan 或 colspan 屬性而跨越到其中的儲存格。
例如,請考慮以下表格標頭的 HTML
<thead>
<tr>
<th rowspan="2" width="15%">Name</th>
<th colspan="2">Position</th>
<th colspan="3">Contact</th>
</tr>
<tr>
<th colspan="3" data-dt-order="disable">HR info</th>
<th colspan="2">Direct</th>
</tr>
</thead>
當透過此方法讀取時,結果將為
[
[
{colspan: 1, rowspan: 2, cell: <th>, title: 'Name'},
{colspan: 2, rowspan: 1, cell: <th>, title: 'Position'},
null,
{colspan: 3, rowspan: 1, cell: <th>, title: 'Contact'},
null,
null
],
[
null,
{colspan: 3, rowspan: 1, cell: <th>, title: 'HR info'},
null,
null,
{colspan: 2, rowspan: 1, cell: <th>, title: 'Direct'},
null
]
]
類型
function table().header.structure( [ columns ] )
- 描述
取得表格標頭的結構
- 參數
名稱 類型 選用 1 columns
是 選擇要取得標頭儲存格的欄。預設情況下,將會擷取表格中的所有欄(無論是否可見)。
- 傳回值
包含物件和 null 值的陣列的陣列,用於描述標頭結構。 請參閱描述以取得完整詳細資訊。
相關資訊
以下選項直接相關,在您的應用程式開發中也可能很有用。