header not align or scroll in bootstrap modal
header not align or scroll in bootstrap modal
t0n1zz
Posts: 32Questions: 19Answers: 0
hi, so i have datatables inside bootstrap modal, and i am using scrollx and scrolly, but the header in the table is not aligned and also not scrolling like the table body.
how to fix that? i tried to add snippet in https://datatables.net/examples/api/tabs_and_scrolling.html
but it is not working (obiviously because that is for bootstrap tabs). so how to fix it?
This discussion has been closed.
Answers
Do you have
width="100%"
applied to your table in HTML?Kevin
yes i have....
Many times that's the issue. Can you post a link showing the problem for troubleshooting?
Kevin
hmm it just a default datatable initialization with scrollx and select extension enabled... in bootstrap modals....
Your Datatables config might be simple / default but the rest of your code is custom to your environment and that is what we need to see.
I found a Bootstrap Modal example and incorporated Datatables into it. With scrollX and select the headers look fine.
You can see it here:
http://live.datatables.net/judogama/1/edit
In order to help you we need more info from you.
Kevin
well i just don't have any idea how to give you the link since i tried it in local environment..
maybe if this information can help:
1. i am using adminlte bootstrap template which quite popular and support datatable
2. i am using select extension from datatables
3. i am now using responsive extension from datatables too, since after trying a few way i decided to use responsive to solve this header missaligned issue, but it is still exist
this is exact same problem like when i using datatable in bootstrap tabs, whats different is there is a workaround in this site for handling bootstrap tabs, but nobody mention anything about bootstrap modals, most of solution is just add widht = 100% (which is already added since first time i using this datatable)
Any chance you can build a test case like the one I built? You can modify what I have if you like.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Telling us what you have doesn't provide enough details to help. Showing us what you have does. A problem that can be seen in action is very helpful. At a minimum post the relevant (CSS and JS includes, HTML for the table and modals and JS) code here.
Kevin
okay after i testing it, i find that the header not aligned if i enabled
scrollY: '50vh',
and i need this feature, so what should i do.... or maybe here i will add my entire table javascript`
var areapanitia = $('#areapanitia');
`
Found this recent thread regarding scrollY and header alignment issues with hidden tables:
https://datatables.net/forums/discussion/41587
Sounds like you may want to use
columns.adjust()
to align the columns when the modal opens.Kevin
Completely agree. If the table is initialised hidden you need to use the method Kevin suggested to make everything align.
Allan
hmm so how to do that column adjust in modal?
My suggestion is to listen for the event that opens the modal then use the
columns.adjust
in that event listener. You may need to use a setTimeout delay like the last example in the discussion I mentioned so the modal has time to display before thecolumns.adjust
executes.Kevin