1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-18 11:52:11 +01:00

Update media/src/core/core.draw.js

Cache row
Avoid array access to childNodes
Move unique calculation outside of loop
Declare all vars at head of function
Cache a[i] in fnShiftCol
This commit is contained in:
Tim Tucker 2012-08-31 13:38:51 -03:00
parent 6fa5559dc3
commit 3cc96cf58f

View File

@ -1,4 +1,3 @@
/**
* Create a new TR element (and it's TD children) for a row
* @param {object} oSettings dataTables settings object
@ -691,10 +690,12 @@ function _fnAddOptionsHtml ( oSettings )
function _fnDetectHeader ( aLayout, nThead )
{
var nTrs = $(nThead).children('tr');
var nCell;
var i, j, k, l, iLen, jLen, iColShifted;
var nTr, nCell;
var i, k, l, iLen, jLen, iColShifted, iColumn, iColspan, iRowspan;
var bUnique;
var fnShiftCol = function ( a, i, j ) {
while ( a[i][j] ) {
var k = a[i];
while ( k[j] ) {
j++;
}
return j;
@ -711,19 +712,18 @@ function _fnDetectHeader ( aLayout, nThead )
/* Calculate a layout array */
for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
{
var iColumn = 0;
nTr = nTrs[i];
iColumn = 0;
/* For every cell in the row... */
for ( j=0, jLen=nTrs[i].childNodes.length ; j<jLen ; j++ )
{
nCell = nTrs[i].childNodes[j];
nCell = nTr.firstChild;
while ( nCell ) {
if ( nCell.nodeName.toUpperCase() == "TD" ||
nCell.nodeName.toUpperCase() == "TH" )
{
/* Get the col and rowspan attributes from the DOM and sanitise them */
var iColspan = nCell.getAttribute('colspan') * 1;
var iRowspan = nCell.getAttribute('rowspan') * 1;
iColspan = nCell.getAttribute('colspan') * 1;
iRowspan = nCell.getAttribute('rowspan') * 1;
iColspan = (!iColspan || iColspan===0 || iColspan===1) ? 1 : iColspan;
iRowspan = (!iRowspan || iRowspan===0 || iRowspan===1) ? 1 : iRowspan;
@ -732,6 +732,9 @@ function _fnDetectHeader ( aLayout, nThead )
*/
iColShifted = fnShiftCol( aLayout, i, iColumn );
/* Cache calculation for unique columns */
bUnique = iColspan === 1 ? true : false;
/* If there is col / rowspan, copy the information into the layout grid */
for ( l=0 ; l<iColspan ; l++ )
{
@ -739,13 +742,14 @@ function _fnDetectHeader ( aLayout, nThead )
{
aLayout[i+k][iColShifted+l] = {
"cell": nCell,
"unique": iColspan == 1 ? true : false
"unique": bUnique
};
aLayout[i+k].nTr = nTrs[i];
aLayout[i+k].nTr = nTr;
}
}
}
}
nCell = nCell.nextSibling;
}
}
}