columns.adjust() Doesn't work when serverside:true.
columns.adjust() Doesn't work when serverside:true.
boidy
Posts: 15Questions: 3Answers: 1
I've read through the API documentation and it states that dataTables will automatically run columns.adjust() on a window.resize event.
(https://datatables.net/reference/api/columns.adjust())
This doesn't seem to be the case when in serverSide mode. Is that by design or is it a bug?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hey,
did you have a look at
autoWidth
?Is this disabled?
Kind Reagrds
Thanks for the suggestion. I've left everything as default when I instantiate the DataTables object, and according to the docs, autoWidth defaults to true. Just in case, I've tried implicitly declaring it as true, but I still get the same issue.
I'm not aware of a bug in that area - but that is not to say there isn't one. Can you link to a test case showing the problem please.
Allan
If no one else has noticed the issue, then its more than likely a fault on my side. The PHP code I'm using to return the JSON data, has been working for months (years even). I assumed that DataTables 1.10 could just use it without me having to update the JSON server. Is it possible that, if there are some fields missing from the expected JSON data, although it draws the table as expected, it breaks some of the other API functions?
It should do, although there is one possible exception. If you use the new
ajax
property, DataTables will also send the server-side parameters in a new, more modern, format. You can use$.fn.dataTable.ext.ajax.legacy
to have it use the old parameters if you want: http://datatables.net/manual/server-side#LegacyYou need to use
columns.defaultContent
to tell DataTables what to do with columns it wants to process but there isn't any data for.Allan
I think the server side mode was a red herring. I've narrowed down the issue to whether or not I use
columnDefs
to hide a column.I've created a test case now, sorry it took so long..
http://live.datatables.net/zuceqok/2/
With the javascript set as:
It successfully hides column [0] which has the header 'User', but when you try to resize the right hand panel, you can see that the columns don't adjust in size. They stay set at what they were when the table was drawn initially.
However, if i don't use
ColumnDefs
:, then the table is drawn and will resize when the containing div is resized, but I of course don't get the user field hidden as desired.I've set the test case up to be as close to my actual page as possible, using the same versions of jQuery and DataTables.
Please close this discussion. After some digging around in the source code, I believe I know what the issue is, and rather than then append it to this discussion, where the question might get lost in the noise, I'd rather re-ask it more succinctly in a new thread, so that it makes it easier for others to find.
@boidy, I too was using columnDefs and was having issues using columns.adjust(). I think I see why yours was not working, and it is because you were not using the correct parameter name for "targets". According to http://www.datatables.net/upgrade/1.10-convert, it should be "columnDefs.targets", not "targets", and "visible" should be "column.visible".
Once I switched mine to use the correct parameter names, i was able to use column.adjust() along with columnDefs
@hysteria I don't quite understand - the code above is correct. The conversion document you link to uses Javascript dotted object notation so
targets
is a property of the child objects ofcolumnDefs
.Allan