Hi,
thanks for your post, and sorry for the trouble.
How are you hiding the columns? With CSS?
About the sorting: I think that the method with the the hidden columns is the best way here. The sorting script simply can not know how you want those “weird” cells to be sorted (by the first number, the second, or the sum?) So, specifying that using a hidden column is the best way.
Regards,
Tobias
Thanks for the reply. I’m hiding the columns using this coding: “columnDefs”: [ { “visible”: false, “targets”: [ 0 ] }, { “orderData”: [ 0 ], “targets”: [ 1 ] }
I had this exact problem too – when using custom commands and hidden columns for column sorting, my tables stopped being responsive and would blow out the right side of web page. I had to add some extra CSS to my theme to fix it, at Tobias’ suggestion.
something like:
.dataTables_wrapper .tablepress {
width: 100% !important;
}
Also, make sure you don’t have columns hidden in the edit screen (pink column) as well as hidden with custom commands, that causes problems as well.
Not sure how to hide the hidden columns from print/pdf as I don’t use that feature.
^That worked a treat, tyvm
Tobias – is there a way to hide the hidden columns from print/pdf etc?
Hi,
sorry for the long delay, I was on holidays and could not reply earlier.
To hide them from print/PDF, you might have to use CSS code, like
.tablepress-id-123 .column-3 {
display: none;
}
Regards,
Tobias
Hey Tobias,
No worries, I’m still working on this 🙂
That code doesn’t work; I found this thread which probably covers the reason: https://datatables.net/forums/discussion/35490/export-pdf-dont-print-hidden-elements
I’m still trying to find a solution. I thought I might have cracked it by using this code: buttons.exportData: [ { “columns”: “visible” } ] but that doesn’t work either.
I also have a new, somewhat bizarre, problem. I have added datatables_fixedheader=top functionality – but it doesn’t work UNLESS I ‘inspect element’ which kicks it into action.
Also something else that has come up – I have made certain columns sortable by ascending order only (using sorting sequence in custom commands) otherwise it messes up certain rows for me because of the format of my table – but this means I lose the sortable icon in the header to show that it is sortable (ie. it still sorts just the triangles aren’t there). Is there any way around this?
Any help on these matters much appreciated!
-
This reply was modified 8 years, 9 months ago by
epitomised.
Hi,
I’m not sure, but these issues could also be caused by the tables being hidden inside the collapseable accordions when the page loads. This can mean that things like the FixedHeader can not properly be initialized.
For the other issues, I’m out of ideas here, as I’m not that familiar with all the internals of the JS code for the Extensions.
Regards,
Tobias
Hi Tobias, How can I sort the table by the first column by default when some access to the page?
Thanks, Carlos
Hi,
add this to the “Custom Commands”:
"order": [[ 0, 'asc' ]]
For more details on this, please see https://datatables.net/reference/option/order
Regards,
Tobias