Hidden Fields need to be export into excel.

Hidden Fields need to be export into excel.

raja424raja424 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);
});

Replies

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    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.

  • Dalex73Dalex73 Posts: 30Questions: 4Answers: 4

    Put a class on the columns say 'export' instead and use that for selecting the colums in exportOptions like,

    "columns": '.export',

  • raja424raja424 Posts: 12Questions: 1Answers: 0

    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.

  • Dalex73Dalex73 Posts: 30Questions: 4Answers: 4

    I assume you added the export class to that column as well? Just remove and it should not be part of the export.

  • raja424raja424 Posts: 12Questions: 1Answers: 0

    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>

This discussion has been closed.