Column width issue
Column width issue
sd_zuo
Posts: 78Questions: 1Answers: 0
I've just downloaded the 1.7.3 version, and the following column configuration brings out an exception.
[code]
var columns = [
{ sTitle: "A", sWidth: "40pt" }
]
[/code]
I used Visual Web Developer to track down the minimized code and see the problem is here
[code]
if(a.aoColumns[b].sWidth!==null)
a.aoColumns[b].nTh.style.width=u(a.aoColumns[b].sWidth);
[/code]
And the evaluation result of "u(a.aoColumns[b].sWidth)" is "40ptpx", which obviously is incorrect.
Please fix this problem by adding the indicated line into the source code.
[code]
if(a.indexOf("em")!=-1||a.indexOf("%")!=-1||a.indexOf("ex")!=-1||a.indexOf("px")!=-1
||a.indexOf("pt")!=-1 // add this line
)return a;
[/code]
Actually I don't think this function is necessary. Why not just check the data type of the width parameter? if number then return widthNumber+"px" otherwise return the width string?
[code]
var columns = [
{ sTitle: "A", sWidth: "40pt" }
]
[/code]
I used Visual Web Developer to track down the minimized code and see the problem is here
[code]
if(a.aoColumns[b].sWidth!==null)
a.aoColumns[b].nTh.style.width=u(a.aoColumns[b].sWidth);
[/code]
And the evaluation result of "u(a.aoColumns[b].sWidth)" is "40ptpx", which obviously is incorrect.
Please fix this problem by adding the indicated line into the source code.
[code]
if(a.indexOf("em")!=-1||a.indexOf("%")!=-1||a.indexOf("ex")!=-1||a.indexOf("px")!=-1
||a.indexOf("pt")!=-1 // add this line
)return a;
[/code]
Actually I don't think this function is necessary. Why not just check the data type of the width parameter? if number then return widthNumber+"px" otherwise return the width string?
This discussion has been closed.
Replies
The reason for the function, is to try and take account of all possibilities - it's not unreasonable for sScrollX (for example) to be given as a string without a unit "sScrollX": "100" for example. DataTables is forgiving enough to add on the pixels, and I think this is probably the right thing to do, since most devs tend not to think about typing in Javascript to much (rightly or wrongly.... :-) ).
Thanks for spotting this, letting me know and the fix!
Regards,
Allan
If you are just trying to determine whether the width is a number in String type. Maybe checking the last character code would be more effective.
[code]
var c = a.charCodeAt (a.length-1);
return (c < 0x30 || c > 0x39)
? a // the last character is not 0-9
: a + "px";
[/code]
[code]
/* Check if the last character is not 0-9 */
var c = s.charCodeAt( s.length-1 );
if (c < 0x30 || c > 0x39)
{
return s;
}
return s+"px";
[/code]
Regards,
Allan