Column mis-alignment
Column mis-alignment
Hi, awesome plugin! I'm having problems with column alignment in different browsers. (ugh..stupid browsers!)
Firefox looks awesome, but IE and Chrome are wrong. All my tests on on Windows.
Wondering if you have any suggestions how to fix/avoid this. Here's my example.
1. goto www.simplecardsort.com
2. Click on "Demo" in the header
3. Click on "view results" (under movie categories)
4. Change the "table type" to "Groups X Card".
Firefox looks awesome, but IE and Chrome are wrong. All my tests on on Windows.
Wondering if you have any suggestions how to fix/avoid this. Here's my example.
1. goto www.simplecardsort.com
2. Click on "Demo" in the header
3. Click on "view results" (under movie categories)
4. Change the "table type" to "Groups X Card".
This discussion has been closed.
Replies
Allan
Thanks for you quick response.
I've downloaded the 1.8 beta and placed it on my server. From what I can tell there isn't any difference in my situation. Is there anything I can do to help debug this? Thanks.
David
Allan
So as I mentioned I've hit this problem myself and I added an (currently) undocumented feature to DataTables to help with the problem. A parameter called "sContentPadding" exists for columns which is a string that will be post fixed to the content in the 'sizing' table.
For example in your table you can add:
[code]
"aoColumnDefs": [
{ "sContentPadding": "mmmm", "aTargets": ["_all"] },
{ "sWidth": "150px", "aTargets": [0] }
]
[/code]
to your initialisation code and that should to the job. In this specific instance I think it's the word "Independence" which is tripping up the calculations. DataTables picks a much longer string for that column, but that string can be broken up while "Independence" cannot. I've added a width to the first columns as will to help this a little - not really needed might might be useful. One other thing you can do is add "white-space: nowrap;" to your CSS for TH and TD cells - which you might or might not want to do.
So basically this is a work around for a known issue in DataTables. The real fix is to use pixel perfect calculations - but sadly that has proven to be exceptionally slow in browsers :-(
Regards,
Allan
On a side note, I'm curious how you arrived at using the text to size the table. Not having tried to do this, I would instinctivly approach it by letting the table size it self, then record the size of the columns, then recreate the header with those sizes. (at the same time fixing the size of the table columns). Is this approach flawed? or does it break down when it's combined with other features?
David
If you are interested the function in question in DataTables is called _fnCalculateColumnWidths. You'll be able to see there the conditions that are placed upon using the original table and the automatic calculation one.
Allan
Did a fix ever turn up for this? My client has literally spent thousands of dollars for me to bang my head on the keyboard trying to fix this, and I have nothing to show for it.
In my case, if I don't try to limit the width of the table, alignment is fine. Any time I constrain it, the misalignment happens.
1) Added ".dataTables_scrollHead table{ table-layout:fixed;}" style;
2) Surrounded all content in my table cells by tag. Like that:
[code]function gridRenderer(oObj) {
var column = oObj.iDataColumn;
var columnAnchor = oObj.oSettings.aoColumns[column].mDataProp;
var content = oObj.aData[columnAnchor];
if (content == "null" || content == null) {
content = "";
}
var result = ""
+ content + "";
return result;
} [/code]- function
and
[code]"aoColumnDefs" : [ {
"fnRender" : gridRenderer,
"bUseRendered" : false,
"sContentPadding" : "W",
"aTargets" : [ "_all" ]
} ] [/code]- attribute ro the table deffinition
For me it was enough to make it work correctly.
@pholord: Nice use of target _all :-).
I think I'll promote sContentPadding to a fully documented option and hopefully put a suitable demo together as it is very useful.
Allan
I am newbee in JS and HTML and I can not explain it, but misalignment was fixed only after I surrounded all content to the "span" containers and added style I specified above. So sContentPadding is only an artifact remaining from my unsuccessful experiments.
By the way, what is wrong with target _all?
Sorry for my poor English.
Best regards.