Column width in IE 11
Column width in IE 11
(trying to report a bug but I can't post to that topic, if there is a better way for me to do this please let me know)
We recently upgraded from DataTables 1.10.5 to 1.10.9. In doing so we discovered a bug when using IE 11.
Column widths are not calculated correctly when the container of the datatable isn't visible at the time the data is loaded.
- IE 11
- Go to this fiddle: https://jsfiddle.net/foraydev/onux4rwx/4/
- Maximize the window
- Run
- The first column is too wide and has no width set. The other columns have a width of 0px
This works correctly in Chrome and used to work in IE before we upgraded.
columns.adjust() also doesn't work until after the show().
If you move the $('#MyContainer').show();
before the DataTable initialization columns have the correct width.
Answers
Have you tried using the adjust() method?
In the documentation, there is a mention that columns widths might be incorrect if the table is hidden, like when it's in a tab or the data is updated which might affect the columns widths.
I tried the above on your fiddle and it seemed to resolve the issue. This would be executed / placed after the table is initialized.
Thank you for the suggestion. I had tried using adjust(), and it only worked for me when I placed it after the call to show().
You said it worked for you. I am wondering if I am missing something. I've updated the fiddle to include the call to adjust(). In IE 11 (wide window) it still isn't working for me.
New version: https://jsfiddle.net/foraydev/onux4rwx/6/
Also, my apologies to you or anyone else that tried yesterday's fiddle. Apparently the Saved version had errors.
Thanks,
-Mont
It should only work after the .show(). That's when all the columns are assigned widths in the DOM.
However this changed some time after 1.10.5. Further, it works fine in Chrome. It is only IE and more recent versions of DataTables that requires either that the data be loaded after the show or that adjust() be called after the show.
It isn't the end of the work but it is an inconvenience over the previous behavior.
OK, I found the bug. In 1.10.9 _fnCalculateColumnWidths() was modified.
Specifically the use of _fnVisibleToColumnIndex() was added to get the correct index of the visible column, taking into account hidden columns. In this for loop there is an incorrect if statement.
Incorrect, as it appear in 1.10.9
The if returns false for the first column when the index of the first column is 0. It should be:
colidx is null when not found, not zero. By adding the != null tables have the correct column widths in IE, even when the table isn't visible when the data is loaded.
I created a pull request.