Updated from 1.10.9 to 1.10.13
Updated from 1.10.9 to 1.10.13
Hi. I just updated and am wondering how to achieve some previous functionality.
I am putting a DataTable on a Bootstrap Modal. In the previous version (1.10.9), this table was beautifully aligned with excellent column spacing based on the content (and based on specified widths via columnDefs). Using the new version (1.10.13), the table is still there, but the column widths are not tailored to the content (nor are they respecting the assigned widths from columnDefs).
I figured that this was something that would be simple to fix by calling table.columns.adjust().draw(), and I was correct. Doing that fixes the issue (and I understand that it cannot calculate widths while hidden before the Modal draw). However, since this is in a Bootstrap Modal, I cannot adjust the columns until the content is drawn, so I am waiting to fire off the adjust().draw() (tying into $('#Modal').on('shown.bs.modal')).
The problem is that now it is jumpy. The Modal slides down with the initial drawing of the table, and then once it has completed its slide, the 'shown.bs.modal' fires and then I can fix the tables. Just somewhat jerky.
I mention all this because in 1.10.9 the initial table draw was already adjusted. That made this all quite nice and smooth. Are there any suggestions on how I can achieve the results I saw in 1.10.9?
Thanks!
This question has an accepted answers - jump to answer
Answers
Do you have
width="100%"
as an attribute for yourtable
? If not, try adding that.If you do, then perhaps try listening for
show.bs.tab
. I'm not sure if Bootstrap puts the elements in the document before triggering that event, but it would certainly be worth checking it.Allan
Hi @allan, and thanks for the response!
I do indeed have
width="100%"
as an attribute on the table. I tried what you suggested, but it did not work. I also realized that there was ashow.bs.modal
event handler as well as theshown.bs.modal
event handler.The elements must be put in the document after triggering
show.bs.modal
because attempting to adjust the tables when that event fires does not work.All in all, the end result of what I am trying to do works fine. Like I mentioned in the original post, I was just more curious than anything why 1.10.9 would self-adjust where 1.10.13 required a little prodding.
Thanks again!
Its possible you might be able to use a little
setTimeout
in theshow
event which would be enough to allow it to be included in the document, but before the animation has faded in.As for way the difference - honestly, I can't remember! There have been quite a few changes in this area, and this sounds like an artefact of that. That it works at all original is somewhat surprising!
Allan