Export all rows if none selected
Export all rows if none selected
Hey,
I wanted the users to have an option to only export selected rows via exportOptions->modifier->selected = true as described here: https://datatables.net/extensions/buttons/examples/print/select.html. That works great when users selects columns, but I find it a bit counter intuitive that 0 rows gets exported when user didn't select any rows (because that file only is kind of useless then, one can only see header cells there). I think a much better default behavior would be to export all rows in that case. I've also found an old discussion when one user was asking for the same (https://www.datatables.net/forums/discussion/29493/using-select-with-buttons-not-working-correctly).
I was wondering if that's doable already (couldn't find it in doc) or what would the best workaround be (hooking to any of button events maybe?)?
This question has an accepted answers - jump to answer
Answers
Hi,
Currently this isn't possible with Buttons, but it is something that I've got on my to do list. I likely won't make it in for 1.2.0 (although I will take a look to see what is involved), but it is something I plan to introduce.
I agree that at the moment it is a bit counter intuitive.
Allan
Hey Alan,
Great to hear it's on your to do list, I hope we can see it soon. Else this is one of the rare things I didn't like about DataTables, all other features work and play together perfectly for server-side processing (was able to customize most of the thing I imagined). Maybe another small minus for indexed column instead of named ones, hope that can also get addressed at some point in the future. :)
Thanks again for great plugin Alan and keep up the good work.
You can name columns using
columns.name
and then use that in thecolumn-selector
.Allan
Sorry if I got that wrong. I am using names but I still think I need to use indexes for:
-ordering:
-for displaying only specific columns to specific users (based on extra data from server):
and custom filters (where I store column index as HTML data attribute):
Is it really possible to use names here instead?
EDIT: after reading the documentation again it seems I can pass a name to column() as well, but I'm still not sure what exactly I should pass (string name doesn't seem to work).
I'm also still not sure about ordering.
Yes for this one - ordering is currently index based, although I do plan to add the option of optionally using names in future.
For the other two, you can use the
:name
selector forcolumn()
. e.g.:table.column( 'myColumn:name' ).search( ... )
.Allan
Thanks you very much Alan for pointing that out. It works perfect. It turned out it didn't work on first try since I had some other code related preventing it to work.
I think we can live with ordering being index based, it would be just cherry on the top.
You could potentially use the
columns().index()
method to get the index based on the name:When I implement it internally, that is more or less what it will be doing.
Allan
Great idea Allan, haven't thought about that.
However, your solution loads the data from the server twice, so I've instead used it inside "preInit.dt" event which works perfect and looks like this (to sort "updated" column before the DT loads):
Thanks again for all your help!
Clever use of
preInit
- thanks for posting back with that.Allan