{hero}

table().header.structure()

Since: DataTables 2.0

Get a Javascript representation of the table header structure.

Description

This method provides the ability to get a Javascript native representation of the HTML structure of the table's header. It allows for complex headers (i.e. cells with colspan and rowspan attributes) and multi-row headers.

The data structure returned has a top level array with one entry for each row in the header. Each row entry is an array of objects or a null value. The object strcture is used to describe a table cell and has the following properties:

  • colspan - The number of columns that the cell spans over
  • cell - The HTML element for the cell (th or td)
  • rowspan - The number of rows that the cell spans
  • title - The title text for the cell.

A null value in place of the object represents a cell that has another spanning into it due to the rowspan or colspan attributes of the previous cells.

As an example, consider the following HTML for a table header:

<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>

When read through this method, the result would be:

[
    [
        {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
    ]
]

Type

function table().header.structure( [ columns ] )

Description:

Get the structure of the table header

Parameters:
Returns:

An array of arrays containing objects and null values that describe the header structure. See the description for full details.

Related

The following options are directly related and may also be useful in your application development.