Hidden Fields need to be export into excel.
Hidden Fields need to be export into excel.
raja424
Posts: 12Questions: 1Answers: 0
Hi I have a table with 40 fields, so I am display only 10 columns for readability but i want export all columns into Excel.
but its is exporting only visible columns even i mentioned hidden columns in list like columns:
including hidden fields [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
but exporting only visible columns
Can any one please help me on the same. below is my code
$(document).ready(function () {
var count = $('#example1').val();
var t = $('#example1').DataTable({
dom: 'Blfrtip',
buttons: [
{
extend: 'excelHtml5',
title: ' Master Details',
text: 'Export to Excel',
exportOptions: {
columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
}
},
],
fnDrawCallback: function (oSettings) {
var that = this;
if (oSettings.bSorted || oSettings.bFiltered) {
this.$('td:first-child', { "filter": "applied" }).each(function (i) {
that.fnUpdate(i + 1, this.parentNode, 0, false, false);
});
}
},
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [0, 5] }, {}
],
});
// debugger;
$("#example1").on('DOMNodeInserted DOMNodeRemoved', function () {
if ($(this).find('tbody tr td').first().attr('colspan')) {
$(".dt-buttons").css('display', 'none');
$(this).dataTable.Buttons.background = 'none';
// return "There is no matching records";
} else {
$(".dt-buttons").css('display', 'inline');
}
});
//this shows the dataTable (simplified)
//dataTable.fnAddData(
// ['a', 'b', 'c', 'd', 'e']
//);
//this hides it (assuming there is only one row)
//dataTable.fnDeleteRow(0);
});
This discussion has been closed.
Replies
you can use the customizeData option in your extended export to put your entire dataset into the export. However, you would have to convert your array of objects to an array of arrays.
Put a class on the columns say 'export' instead and use that for selecting the colums in exportOptions like,
"columns": '.export',
Tq..Working fine but have one more concern the last column also exporting into excel ,
I want restrict that column because it is a action link text.
I assume you added the export class to that column as well? Just remove and it should not be part of the export.
I am not able to fetch the model data in export excel only header is comming...
i have used "columns": '.export', also
<th style="text-align: center" hidden="hidden">YetToJoin </th>
<td style="text-align: left" class="ellipsis " hidden="hidden">
<span title="@item.Subvertical">
@Html.HiddenFor(modelItem => item.Subvertical)</span>
</td>