Select columns to export!
Select columns to export!
I'm having a problem with the export, it works perfect but i don't know how to do what i want to do.
var table = $('#ID_TrackOrderoverview').dataTable( {
"dom": 'Brtip',
"stateSave": true,
"buttons": [
{
"extend": 'excelHtml5',
"autoFilter": true,
"sheetName": 'Exported data',
"exportOptions": {
columns: '.show'
}
},
{
"extend": 'columnsToggle',
columns: '.show'
}],
I'm using a class "Show" to have the buttons that i need in the columnsToggle.
But now i want to show only some colmns and i cannot use index or names cause if the user has less privileges the columns available will change. I want to use a class like class:export but i'm already using it to show specific buttons.
I need to show 2 hidden values and several other columns and i cannot use index or names as reference.
I searched a lot and i couldnt find an answer, a class will be great like i do with tooglebuttons.
Regards.
Answers
You need to apply the class to the column headers before initialising the DataTable for that to work - Buttons column visibility actually initialises before the column classes are added by
columns.className
which is why you are running into an issue here.So you could use:
Allan
Hi allan,
I'm actually defining all the columns during he initialization of the datatable. And it works perfectly the export and the ToogleButtons, the problem is that i'm using the Class attribute for showing the ToogleButtons, now i need something similar that let me export some columns but i cannot use index or name since the table changes if u have more rights.
Right now is exporting perfect but the oes that i'm using with the class show, Is there anyway to do something similar?
Thanks for ur replay
The only way would be to initialise Buttons after the DataTables initialisation. Which is quite possible.
Allan
Hi allan,
if i do it like that how i'm going to identify the columns that i want?
is going to keep bringing me the columns with the show class i thought about adding a property called Export: true to the columns i want to use and somehow use it there,
Regards
It should work exactly that like. Your Buttons initilaisation is the same (although you pass it in as the second parameter to the Buttons constructor rather than using
buttons
in the table configuration object).Allan
Hi allan thanks for ur replies.
I don't know if i'm doing it right but i create an attribute in aoColumns called bExport and now i'm trying to get it to have the columnsthat i want to show in the excel. Is this the rigt way, anyway i'm getting an error table.columns is not working.
Regards
That suggests it isn't the right way . And no - I wouldn't expect this method to work -
table.columns
is a function, not an array.Before you were using
columns: '.show'
and you said that was being assigned bycolumns.className
. That's the way to do it.Allan