1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-12-01 13:24:10 +01:00

Updated: Modification to the way table width is handled - if the 'width' attribute is on the table tag, then we use that to size the table. This makes having a table width of 100% much easier than before. The reason we need to do this is that there just doesn't appear to be a good way to get the relative width from stylesheets across browsers.

This commit is contained in:
Allan Jardine 2011-12-15 09:43:31 +00:00
parent 8714f7cc0e
commit 91858f9e86
3 changed files with 25 additions and 5 deletions

View File

@ -28,7 +28,7 @@
<h1>Live example</h1>
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">
<thead>
<tr>
<th>Rendering engine</th>

View File

@ -3416,6 +3416,7 @@
var iColums = oSettings.aoColumns.length;
var i, iIndex, iCorrector, iWidth;
var oHeaders = $('th', oSettings.nTHead);
var widthAttr = oSettings.nTable.getAttribute('width');
/* Convert any user input sizes into pixel sizes */
for ( i=0 ; i<iColums ; i++ )
@ -3550,6 +3551,10 @@
{
nCalcTmp.style.width = _fnStringToCss( nWrapper.offsetWidth );
}
else if ( widthAttr )
{
nCalcTmp.style.width = _fnStringToCss( widthAttr );
}
nCalcTmp.style.visibility = "hidden";
/* Scrolling considerations */
@ -3590,7 +3595,7 @@
iCorrector++;
}
}
nCalcTmp.style.width = _fnStringToCss( iTotal );
oSettings.nTable.style.width = _fnStringToCss( iTotal );
}
@ -3608,12 +3613,17 @@
iCorrector++;
}
}
var cssWidth = $(nCalcTmp).css('width');
oSettings.nTable.style.width = (cssWidth.indexOf('%') !== -1) ?
cssWidth : _fnStringToCss( $(nCalcTmp).outerWidth() );
nCalcTmp.parentNode.removeChild( nCalcTmp );
}
if ( widthAttr )
{
oSettings.nTable.style.width = _fnStringToCss( widthAttr );
}
}

View File

@ -45,6 +45,7 @@ function _fnCalculateColumnWidths ( oSettings )
var iColums = oSettings.aoColumns.length;
var i, iIndex, iCorrector, iWidth;
var oHeaders = $('th', oSettings.nTHead);
var widthAttr = oSettings.nTable.getAttribute('width');
/* Convert any user input sizes into pixel sizes */
for ( i=0 ; i<iColums ; i++ )
@ -179,6 +180,10 @@ function _fnCalculateColumnWidths ( oSettings )
{
nCalcTmp.style.width = _fnStringToCss( nWrapper.offsetWidth );
}
else if ( widthAttr )
{
nCalcTmp.style.width = _fnStringToCss( widthAttr );
}
nCalcTmp.style.visibility = "hidden";
/* Scrolling considerations */
@ -219,7 +224,7 @@ function _fnCalculateColumnWidths ( oSettings )
iCorrector++;
}
}
nCalcTmp.style.width = _fnStringToCss( iTotal );
oSettings.nTable.style.width = _fnStringToCss( iTotal );
}
@ -237,12 +242,17 @@ function _fnCalculateColumnWidths ( oSettings )
iCorrector++;
}
}
var cssWidth = $(nCalcTmp).css('width');
oSettings.nTable.style.width = (cssWidth.indexOf('%') !== -1) ?
cssWidth : _fnStringToCss( $(nCalcTmp).outerWidth() );
nCalcTmp.parentNode.removeChild( nCalcTmp );
}
if ( widthAttr )
{
oSettings.nTable.style.width = _fnStringToCss( widthAttr );
}
}