If autoWidth=false, can we avoid the second rendering after adjusting the column sizing?
If autoWidth=false, can we avoid the second rendering after adjusting the column sizing?
In our tables we set the autoWidth
option to false
, because we implemented a column sizing algorithm with custom requirements. Also, some of our tables are rather big (~50 columns, see screenshot of the DataTables debugger). For those we need to have an eye on rendering performance in IE.
One issue is that the reflow for getting the scrollHeight
of the table body takes ~800ms:
var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
This function is called two times: Once when the table is drawn the first time and then after adjusting the column sizing (_fnAdjustColumnSizing()
). The latter is done even with autoWidth=false
and the only possibility we see to prevent this is setting scrollX
and scrollY
to ''
(empty string):
var scroll = settings.oScroll;
if ( scroll.sY !== '' || scroll.sX !== '')
{
_fnScrollDraw( settings );
}
But this would break our custom column sizing. So we're wondering whether it'd make sense to do the second _fnScrollDraw()
only if autoWidth=true
:
if ( settings.oFeatures.bAutoWidth !== false )
{
...
var scroll = settings.oScroll;
if ( scroll.sY !== '' || scroll.sX !== '')
{
_fnScrollDraw( settings );
}
}
_fnCallbackFire( settings, null, 'column-sizing', [settings] );
What do you think? It would really be great to avoid this expensive second rendering, which has no effect with autoWidth=false
.
This question has an accepted answers - jump to answer
Answers
You could try that in a fork of the code, but the reason it is in there is to try an ensure that the column alignment between the header and body (and footer if there is one) is consistent. I've found that to be easily the hardest part of DataTables!
Allan
Ah OK,
autoWidth=false
does not mean, that the columns are not sized at all, but instead they are sized based on the data of the current page.That means, the second rendering could only be avoided if we know that the column widths do not change on scroll, like in our case. Thx for clarifying.