Column name not showing in Data Export
Column name not showing in Data Export
parismiguel
Posts: 7Questions: 3Answers: 0
Hi!
I'm trying to get my column names printed whenever I use any export option; however, it's not showing at all.
Could you please help me?
Thank you!
Here is my HTML(header section only):
<thead>
<tr class="filters">
<th class="no-sort" style="padding:0 22px 5px 8px">
<input type="checkbox" class="flat-orange" name="chkSelectAll" id="IdchkSelectAll" />
</th>
<th id="filter_col1" data-column="1">
<input type="text" class="col_filter" id="col1_filter" placeholder="@Html.DisplayNameFor(model => model.SsNombre)" disabled>
</th>
<th id="filter_col2" data-column="2">
<input type="text" class="col_filter" id="col2_filter" placeholder="@Html.DisplayNameFor(model => model.Estado)" disabled>
</th>
<th id="filter_col3" data-column="3">
<input type="text" class="col_filter" id="col3_filter" placeholder="@Html.DisplayNameFor(model => model.Tipo)" disabled>
</th>
<th id="filter_col4" data-column="4">
<input type="text" class="col_filter" id="col4_filter" placeholder="@Html.DisplayNameFor(model => model.Prioridad)" disabled>
</th>
<th id="filter_col5" data-column="5">
<input type="text" class="col_filter" id="col5_filter" placeholder="@Html.DisplayNameFor(model => model.Criticidad)" disabled>
</th>
<th id="filter_col6" data-column="6">
<input type="text" class="col_filter" id="col6_filter" placeholder="@Html.DisplayNameFor(model => model.Sitio.SitioNombre)" disabled>
</th>
<th class="no-sort"></th>
</tr>
</thead>
And here is my jquery:
$("#example1").DataTable({
"dom": 'Brtip',
"buttons": [
{
extend: 'copy',
text: '<i class="fa fa-files-o" style="color:orange;"></i>',
titleAttr: 'Copiar',
title: 'Efficax Export'
},
{
extend: 'excel',
text: '<i class="fa fa-file-excel-o" style="color:green;"></i>',
titleAttr: 'Excel',
title: 'Efficax Export'
},
{
extend: 'csv',
text: '<i class="fa fa-file-text-o" style="color:blue;"></i>',
titleAttr: 'CSV',
title: 'Efficax Export'
},
{
extend: 'pdf',
text: '<i class="fa fa-file-pdf-o" style="color:brown;"></i>',
titleAttr: 'PDF',
title: 'Efficax Export'
},
{
extend: 'print',
text: '<i class="fa fa-print" style="color:black;"></i>',
titleAttr: 'Imprimir',
title: 'Efficax Export'
}
],
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json",
buttons: {
copyTitle: 'Copiando a la Memoria',
copyKeys: 'Presione <i>ctrl</i> y <i>\u2318</i> + <i>C</i> para copiar la información de la Tabla a la memoria. <br><br>Para anular, haga click en el título de la ventana emergente.',
copySuccess: {
_: 'Copiado %d filas',
1: 'Copiado 1 fila'
}
}
},
"scrollX": 600,
"order": [],
"columnDefs": [{
"targets": 'no-sort',
"orderable": false
}
]
});
This question has accepted answers - jump to:
This discussion has been closed.
Answers
The export options strip out any html before exporting the data. In your header you are using input tags so they will getting removed prior to any export.
You have three options
* You could use a data formatter. This example shows how to use a body formatter to extract data from a node. You could also use a header formatter. This feature is currently only available in the nightly version of buttons.
* The second option is to use a second header row with the column names.
* Third option is to just put the columns names in the <th> tags before the input.
Thanks
Tom
Hi Tom, thank you for your reply!
It makes totally sense what you say... I suspected something about those inputs from the beggining... what a dilemma, I need them for my filters.
Anyways, I've tried your recommendations as follows but I think I'm not interpreting as I should be:
I'm not sure how to use body formatter for my purposes... here is my best guessing but it's not working at all:
About header formatter, I rather prefer not to use a nightly version because I'm not very experimented and I want to avoid further unknown risks.
Well, that's the most detailed info that I can provide hoping this can aid to other buddies as well. Please help me to sort out this las challenge!
Warm regards,
Paris
Ok... this works as I expected! I've just encapsulated my additional th name within a hidden "span" tag. I.e.:
<span class="hidden">@Html.DisplayNameFor(model => model.Estado)</span>
Maybe it's neither the most efficient nor the most elegant way but it works... .thank you Tom for pointing me into the right direction!
P.D. It could be very instructive anyways if you are able to solve this using your first two alternatives.
Have a great day!
PAris
Clever - nice solution
You wouldn't use a body formatter for the header, but rather use a header formatter. You might do something like:
Allan
Thank you Allan... It's fantastic to learn from buddies that know more than me like yourself!