Column Headers Disappear when hiding table until data is formatted when using scrollx and scrolly
Column Headers Disappear when hiding table until data is formatted when using scrollx and scrolly
vbprogrammer
Posts: 8Questions: 2Answers: 0
When using display:none in table style and using initcomplete function to show table and having scrollX true and scrollY value set, the table loads as expected but the column headers are missing. If I remove scrollX and scrollY, then it works as expected but I need it to work with scrollX and scrollY enabled. Data is Client-Side provided.
new DataTable('#licenseTable', {
processing: true,
fixedColumns: {
start: 3
},
//scrollCollapse: true,
// scrollX: true,
// scrollY: 450,
searching: true,
fixedHeader: true,
This question has accepted answers - jump to:
Answers
If you have the table hidden during initialisation, it can't perform any width calculations. You need to call
columns.adjust()
when you make the table visible.DataTables 2.2, which I plan to release next week, has a way to doing that automatically .
Allan
First: Thank you for your help! If it is easier to wait until you release the update, I am fine with that but here is what I have done...
i adjusted the code to add the table variable and then tried the columns.adjust and I get console errors stating : Query.Deferred exception: Cannot read properties of undefined (reading 'columns') TypeError: Cannot read properties of undefined (reading 'columns') and jquery-3.7.1.js:3793 Uncaught TypeError: Cannot read properties of undefined (reading 'columns').
Table HTML
Table JavaScript
I think problem is you are trying to use the variable
tbl_licenseTable
ininitComplete
before the variable has been created. Try usingthis.api()
instead, like this:Kevin
Thank you. That fixed the error in the console but the column headers are still not displayed. Other than that, the table displays as expected.
Right. When scrolling features are anabled Datatables clones the header, hides the original and creates a new
table
with the cloned header to enable the scrolling features. One option is to traverse the document to show thistable
. For example:https://live.datatables.net/vuziyehe/1/edit
Kevin
A better option might be to hide the wrapping
div
. This way the Datatables elements like search and page length won't be visible until thediv
is displayed. Updated example:https://live.datatables.net/pisoyema/1/edit
Kevin
And that fixed it completely!!!
Thank You!