Small Width Calculation Glitch when Toggling Hidden Columns
Small Width Calculation Glitch when Toggling Hidden Columns
bryceray1121
Posts: 65Questions: 0Answers: 0
I've had this problem for a while and have never really found a solution for it. The problem in general is pretty minor. My tables load by default with some columns hidden. I then have a button that toggles the hidden columns to be visible and hidden again.
Initially when the table loads it loads perfectly. However, when I hit the toggle button to make the hidden columns visible a small white space appears to the right of the table (but within dataTables_scrollBody). This space is identical to the width of a vertical scroll bar and is on the right side of the table. It appears as if the calculation of the data table (the child to dataTables_scrollBody) is calculating the wrong width.
This happens with tables whose height does not require a scroll bar. If a table does require a scroll bar because it has sufficient rows then this is not an issue.
Changing the columns back to hidden (after making them visible) does not fix the problem, the space appears to stay there until I reload the page.
Note, that this also happens when I click on the header of a column to sort it. The sort functionality I use is the default sort functionality built into the library.
Here is my visibility toggle function:
[code]
hieviews.fnShowHide = function( obj, tag, textVal){
var tmpTable = $jq(tag).dataTable();
var tmpCols = tmpTable.fnSettings().aoColumns;
var bVis = false;
for (var i=0;i < (tmpCols.length);i++) {
if ($jq(tmpCols[i].nTh).hasClass("dataTables_notVisible")) {
bVis = tmpTable.fnSettings().aoColumns[i].bVisible;
tmpTable.fnSetColumnVis( i, bVis ? false : true );
}
}
obj.innerHTML = bVis ? textVal[0] : textVal[1];
//tmpTable.fnAdjustColumnSizing();
//tmpTable.fnDraw();
}
[/code]
I have tried every combination of fnAdjustColumnSizing() and fnDraw() in an effort to force a more accurate redraw (and width calculation). However, none of these combinations eliminated the space.
Here is a link to the screenshot of the problem.
http://www.flickr.com/photos/26503296@N04/5364741908/
Initially when the table loads it loads perfectly. However, when I hit the toggle button to make the hidden columns visible a small white space appears to the right of the table (but within dataTables_scrollBody). This space is identical to the width of a vertical scroll bar and is on the right side of the table. It appears as if the calculation of the data table (the child to dataTables_scrollBody) is calculating the wrong width.
This happens with tables whose height does not require a scroll bar. If a table does require a scroll bar because it has sufficient rows then this is not an issue.
Changing the columns back to hidden (after making them visible) does not fix the problem, the space appears to stay there until I reload the page.
Note, that this also happens when I click on the header of a column to sort it. The sort functionality I use is the default sort functionality built into the library.
Here is my visibility toggle function:
[code]
hieviews.fnShowHide = function( obj, tag, textVal){
var tmpTable = $jq(tag).dataTable();
var tmpCols = tmpTable.fnSettings().aoColumns;
var bVis = false;
for (var i=0;i < (tmpCols.length);i++) {
if ($jq(tmpCols[i].nTh).hasClass("dataTables_notVisible")) {
bVis = tmpTable.fnSettings().aoColumns[i].bVisible;
tmpTable.fnSetColumnVis( i, bVis ? false : true );
}
}
obj.innerHTML = bVis ? textVal[0] : textVal[1];
//tmpTable.fnAdjustColumnSizing();
//tmpTable.fnDraw();
}
[/code]
I have tried every combination of fnAdjustColumnSizing() and fnDraw() in an effort to force a more accurate redraw (and width calculation). However, none of these combinations eliminated the space.
Here is a link to the screenshot of the problem.
http://www.flickr.com/photos/26503296@N04/5364741908/
This discussion has been closed.
Replies
Allan
I don't think its quite the same problem as the other thread. The problem occurs if I hide/show initially hidden columns, sort a column, or filter a table. So it seems to me that it is a problem associated with common functionality between methods that alter the table.
Is there any more information I can provide you to aide you in better understanding this problem?
Thanks,
Allan
Thanks for looking into this, I appreciate it.
Allan
Here is my datatable initiation:
[code]hieviews.renderDataTable = function(selector) {
var out = [];
var tables = $jq(selector);
var sorting;
for ( var i=0, iLen=tables.length ; i= 0){
sorting = [ defaultCol, 'desc' ];
}else{
sorting = [0,'desc'];
}
var oTable2 =$jq(tables[i]).dataTable({
"aaSorting": [ sorting ],
"sScrollY": "200px",
"sScrollX": "100%",
"bScrollCollapse":true,
"sDom": 'rt<"bottom"flp>',
"bPaginate": false,
"bStateSave": false,
"aoColumnDefs": [
{"bSearchable": false, "bSortable": false, "aTargets": ["dataTable-exclude"]},
{"bVisible":false, "aTargets" : ["dataTables_notVisible"]}
]
} );
out.push( oTable2 );
}
[/code]
Thanks,
Allan
[code]
sample
DetailsPrint
-/+
Column
Column
Column
Column
Column
Data
Data
Data
Data
Data
Data
Data
Data
Data
Data
Data
Data
Data
Data
Data
Search:
[/code]
1.Load the page with the tables in the browser.
2.Open up firebug so it is viewable in the lower portion of screen.
3.Refresh the page.
4.When the page reloads the firebug extension should still be visible. At this point the tables display without error. However, if you then close the firebug extension (thus increasing the screen real estate) the bug occurs.
Don't know if this helps any, but I thought it was interesting.