* Use the DOM source to create up an array of header cells. The idea here is to * create a layout grid (array) of rows x columns, which contains a reference * to the cell that that point in the grid (regardless of col/rowspan), such that * any column / row could be removed and the new grid con
(settings, thead, write)
| 3615 | * @memberof DataTable#oApi |
| 3616 | */ |
| 3617 | function _fnDetectHeader(settings, thead, write) { |
| 3618 | var columns = settings.aoColumns |
| 3619 | var rows = $(thead).children("tr") |
| 3620 | var row, cell |
| 3621 | var i, k, l, iLen, shifted, column, colspan, rowspan |
| 3622 | var isHeader = thead && thead.nodeName.toLowerCase() === "thead" |
| 3623 | var layout = [] |
| 3624 | var unique |
| 3625 | var shift = function (a, i, j) { |
| 3626 | var k = a[i] |
| 3627 | while (k[j]) { |
| 3628 | j++ |
| 3629 | } |
| 3630 | return j |
| 3631 | } |
| 3632 | |
| 3633 | // We know how many rows there are in the layout - so prep it |
| 3634 | for (i = 0, iLen = rows.length; i < iLen; i++) { |
| 3635 | layout.push([]) |
| 3636 | } |
| 3637 | |
| 3638 | for (i = 0, iLen = rows.length; i < iLen; i++) { |
| 3639 | row = rows[i] |
| 3640 | column = 0 |
| 3641 | |
| 3642 | // For every cell in the row.. |
| 3643 | cell = row.firstChild |
| 3644 | while (cell) { |
| 3645 | if (cell.nodeName.toUpperCase() == "TD" || cell.nodeName.toUpperCase() == "TH") { |
| 3646 | var cols = [] |
| 3647 | |
| 3648 | // Get the col and rowspan attributes from the DOM and sanitise them |
| 3649 | colspan = cell.getAttribute("colspan") * 1 |
| 3650 | rowspan = cell.getAttribute("rowspan") * 1 |
| 3651 | colspan = !colspan || colspan === 0 || colspan === 1 ? 1 : colspan |
| 3652 | rowspan = !rowspan || rowspan === 0 || rowspan === 1 ? 1 : rowspan |
| 3653 | |
| 3654 | // There might be colspan cells already in this row, so shift our target |
| 3655 | // accordingly |
| 3656 | shifted = shift(layout, i, column) |
| 3657 | |
| 3658 | // Cache calculation for unique columns |
| 3659 | unique = colspan === 1 ? true : false |
| 3660 | |
| 3661 | // Perform header setup |
| 3662 | if (write) { |
| 3663 | if (unique) { |
| 3664 | // Allow column options to be set from HTML attributes |
| 3665 | _fnColumnOptions(settings, shifted, $(cell).data()) |
| 3666 | |
| 3667 | // Get the width for the column. This can be defined from the |
| 3668 | // width attribute, style attribute or `columns.width` option |
| 3669 | var columnDef = columns[shifted] |
| 3670 | var width = cell.getAttribute("width") || null |
| 3671 | var t = cell.style.width.match(/width:\s*(\d+[pxem%]+)/) |
| 3672 | if (t) { |
| 3673 | width = t[1] |
| 3674 | } |
no test coverage detected