Can't figure out why sScrollY corrupts the Columns's size and alignement
Can't figure out why sScrollY corrupts the Columns's size and alignement
ciaoben
Posts: 21Questions: 0Answers: 0
I need to use sScrollX and ScrollY property for my datatables. But simply adding one of this property cause a lot of problems with size and alignemnt of the columns.
Here is a simple re-production of my table. In reality i use an Ajax call to fill my table. but i replied some data for this example:
http://live.datatables.net/Ikis/1/edit
Here is a pic of my real page:
https://www.evernote.com/shard/s44/sh/5a7c2a79-d265-4461-965b-9a65625cdf6d/855d7875b0c9e960cc533e82c5717622
Can someone explain me this behavior ?
Here is a simple re-production of my table. In reality i use an Ajax call to fill my table. but i replied some data for this example:
http://live.datatables.net/Ikis/1/edit
Here is a pic of my real page:
https://www.evernote.com/shard/s44/sh/5a7c2a79-d265-4461-965b-9a65625cdf6d/855d7875b0c9e960cc533e82c5717622
Can someone explain me this behavior ?
This discussion has been closed.
Replies
Allan
Even if you try to use it in my live.Datatables, it doesn't work. Can you please me show an example in my fiddle?
http://live.datatables.net/iQeZ/1/edit
> Uncaught ReferenceError: oTable is not defined
Probably isn't going to help. Fixed: http://live.datatables.net/iQeZ/2/edit
It seems to work either way for me.
Allan
[code]
"sAjaxSource":"/async_popula/" ,
"sAjaxDataProp":"dati.0"
[/code]
then, i'm giving the appropriate value to each column:
[code]
"aoColumns": [
{ "mData": "codice"
},
{ "mData": "descrizione"
},
{ "mData": "flag_banca"
}
[/code]
Tell me if i'm wrong... the problem here is that dataTable calculate the size of the visibile header when the data are not load yet, right?!
If it is the problem, how do you suggest to use fnAdjust? or any other solution?
DataTables 1.9- does not wait for the data to be loaded. DataTables 1.10 does.
With 1.9- you can use:
[code]
fnInitComplete: function () {
this.fnAdjustColumnSizing();
}
[/code]
to adjust column sizing once the data has been loaded. This doesn't have anything to do with corruption of the header - that is something else.
Allan
I write the ajax request in order to write the table body on the html page. After that, i've made a :
[code]
$('#clickme').on('click', function(){
datatabla();
});
[/code]
which on click fires the dataTable() initialisation:
[code]
function datatabla(){
var table=$('#datatable_pagamento').dataTable( {
"sScrollY":200
});
[/code]
This should give no problems, because the dataTable function is the simpliest of the dataTable() usage. But i don't know why, this is the result:
https://www.evernote.com/shard/s44/sh/4f20780b-5ecb-4894-abaf-45b99dde4bfc/6305c0148ecf8b3d3b4e11df91132db7/res/23cfb05b-3bcb-4430-b1b4-34cf02e786be/resource.jpg?resizeSmall&width=832
i try to add the Adjust, but literally NOTHING happens.
I'm not using any other library, the page of the screenshot have no style (except a border: solid 1px black) and no other js library embed beside datatable.
i'm losing my mind
> Access denied.
when clicking on your evernote link.
I really need a link to a page showing the problem to be able to help. I'm just guessing at the moment and the live site links above appear to work as expected unless I'm missing something.
Allan
http://acs-web.it/test/esperimenti.php
i left out the ajax call, but the problem is the same. I'll wait for your opinion :)
Can you try with DataTables 1.10 a dev version of which is on the downloads page ( http://datatables.net/download ). I believe the issue is fixed there (I've just tried downloading your page and it works okay - or at least it would when Ajax loading with object data).
Allan
Edit: i confirm to you that on chrome doesn't work, while on firefox works properly... how can i do?
Here the link again with datatable 1.10: http://acs-web.it/test/esperimenti.php
You have `border-collapse: collapse` set in this example. If you remove that it should work. Border collapse is simply impossible to deal with due to the way the browser layout algorithm works.
The header table contains different information than the body table, so even although the widths are applied exactly the same (which you will be able to see in the inspector) they are shown with different widths. Removing the collapse property will fix that.
Allan
anyway, i updated the link, no border-collapse now, you can refresh the page and try (i've also cleaned up the js file, know you can read it easily)
This is the latest DataTables stylesheet which you might find useful: https://github.com/DataTables/DataTables/blob/master/media/css/jquery.dataTables.css
Here is a new link with the new css, and the cellspacing: http://acs-web.it/test/esperimenti.php
You appear to have added additional CSS to your example `box-sizing: content-box;` for example.
Can you make a page with my code but corrected in your way?? so i could see the effective differences and if there are mistake in my code.
I've just spent the last hour and a half trying to figure out what is going wrong here, and its a bit of a nightmare. Basically, DataTables is calculating the column widths correctly, and then also applying them correctly to both the header and body tables. However - because there is different padding and different font-weight on the header and the body tags, the browser will realign the layout, completely ignoring the sizes set by DataTables.
I've come up with three workarounds thus far:
- Use the same padding and font-weight on both:
http://datatables.net/clients/ciaoben/acs-web.it-border-font/test/esperimenti.php.html
- Use white-space: nowrap:
http://datatables.net/clients/ciaoben/acs-web.it-nowrap/test/esperimenti.php.html
- Use `contentPadding` to add extra space into the calculated cell widths:
http://datatables.net/clients/ciaoben/acs-web.it-contentPadding/test/esperimenti.php.html
I'd obviously rather we didn't need a workaround - but I'm struggling at the moment to see how to fix it properly in the core. This needs more work unfortunately, and I rather suspect its going to take a good deal of time to get right.
Allan
So the fix (I guess it seems obvious now) is to have that same content in the body's header cells, but wrapped in a div which is height:0. Test case showing this "real" fix: http://datatables.net/clients/ciaoben/acs-web.it-fixed/test/esperimenti.php.html
Unfortunately 1.10.0-beta.1 hit today :-(. So it won't be in that. But I will commit this in tomorrow for the next beta unless I can think of some reason why it wouldn't work (it will slow performance down a little, but not too much I think).
Allan
[code]"sAjaxSource":[/code]
Because this will make calculate the width before the data are effectively there, right?
i've tried and the columns are wrongly calculate again.. i also tried to use a click button with fnAdjustColumnSizing(); but nothing happens.
here the code for the js with ajax load:
[code]
$(document).ready( function () {
var table=$('#datatable_pagamento').dataTable( {
"bSort":false,
"sScrollY":300,
"sScrollX":true,
scrollCollapse: true,
fnInitComplete: function () {
this.fnAdjustColumnSizing();
},
"bServerSide": true,
"sAjaxSource": "/async_datatable_pagamenti/",
"fnServerParams": function (aoData) {
aoData.push({
"name": "id_login",
"value": $("#h_id_login").val()
});
},
columnDefs: [
{ targets: "_all", contentPadding: "mmmmm" }
]
} );
table.fnAdjustColumnSizing();
[/code]
but fnAdjustColumnSizing seems to have no effects... any suggestion?
[code]
olumnDefs: [
{ targets: "_all", contentPadding: "mmmmm" }
]
[/code]
and the columns seem to be better sized and alignement.
Just to understand, what does exactly that property do?
Can you link me to an updated test page showing that please?
Thanks,
Allan
http://i.imgur.com/StqmbPe.png
here you can see how the columns are not aligned at all.
But when i click on a element like pagination number, or the menu of how many items will be showed, all goes in its place, and became perfect:
http://i.imgur.com/EZUx88U.png
The code is the same i've showed you on the previous post. Except fot fnInitComplete that i 've removed, as you suggested.
I've just committed the fix that I suggested last night, but obviously there is still a bit more work to be done here...
Allan
So it's obvious that the problem in the calculus it's hide()'s fault. In fact, moving the hide function in fnInitComplete make the magic happen :D
i really, really thank you for your precious help and for having correct the bug!
I would like to ask for a little advice, tell me if it's better to open another forum's post:
Like i said before, i've a lot of datatables and i'm rewriting all properties and function a lot of times! There is a way to write some basic datatable config and extend with the particular needs every time i make a new one?
Basically have a basic Datatable configuration and then extend it for every special case.
Good to hear that this is working for you now :-).
The fix that I've put in will be in 1.10.0 final and beta.2 - I'm planning to drop beta.2 early next week.
> There is a way to write some basic datatable config and extend with the particular needs every time i make a new one?
jQuery's $.extend method come into play here. What I would suggest doing is modifying DataTables defaults with something like:
[code]
$.extend( true, $.fn.dataTable.defaults, {
paging: true,
ordering: false
// etc
} );
[/code]
Then you can just initialise the table, and pass in extra override options if you want.
Allan