mirror of
https://github.com/DataTables/DataTables.git
synced 2024-11-29 11:24:10 +01:00
New: Add the ability to read size information from HTML elements for columns
- Column width is always a particularly difficult one to get quite right. In this case, the fix is to have DataTables read column width information from the `width` or `style` attributes of a column header cell, if that information is present. If it is, it is treated as sWidth is (although user supplied sWidth can override). That is it say that it will be applied to the column width calculation table. - The remaining gap is if a developer assigns a width using css classes. We can't get that information, so we fall into the old problem. - This change comes about from the discussion in http://datatables.net/forums/discussion/19089 and the fiddle here: http://jsfiddle.net/EysLd/1/ - What is happening in the test case is that the calculation table is being created, but it is then stripped of widths due to this commit: https://github.com/DataTables/DataTables/commit/6a9e324 . That was to allow DataTables column headers to have their applied size removed, so a new size could be calculated. Only sWidth would override that - now the width and style attributes will as well
This commit is contained in:
parent
c76bdb3294
commit
6fbd3ba8e6
@ -1 +1 @@
|
||||
f06ee8a003374ac5653079a2fc2587e496f7480f
|
||||
41dc47b2d50e3bf87e4266365c24257c64a5e3ae
|
||||
|
15
media/js/jquery.dataTables.js
vendored
15
media/js/jquery.dataTables.js
vendored
@ -526,6 +526,21 @@
|
||||
var oCol = oSettings.aoColumns[ iCol ];
|
||||
var oClasses = oSettings.oClasses;
|
||||
|
||||
// Try to get width information from the DOM. We can't get it from CSS
|
||||
// as we'd need to parse the CSS stylesheet. `width` option can override
|
||||
if ( ! oCol.sWidthOrig ) {
|
||||
var th = $(oCol.nTh);
|
||||
|
||||
// Width attribute
|
||||
oCol.sWidthOrig = th.attr('width') || null;
|
||||
|
||||
// Style attribute
|
||||
var t = (th.attr('style') || '').match(/width:\s*(\d+[pxem%])/);
|
||||
if ( t ) {
|
||||
oCol.sWidthOrig = t[1];
|
||||
}
|
||||
}
|
||||
|
||||
/* User specified column options */
|
||||
if ( oOptions !== undefined && oOptions !== null )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user