I'm using datatable in a project and it's running 100%. What I need is that at the moment of exporting to PDF and excel I do not want to export the columns in which I do not allow sort or search, other than columns in which I have buttons and at certain moments images.
usando exporteOptions: { colums: []}
right, but I wanted to use it as I mentioned above, so I can reuse the code on other pages.
My code looks like this:
myTable = $('#dynamicTableDesc').dataTable({
sAjaxSource: "/@controller/List",
bServerSide: true,
bPaginate: true,
pageLength: 50,
dom: '<"html5buttons"B>lTfgitp',
buttons: [
//{ extend: 'copy' },
//{ extend: 'csv' },
{ extend: 'excel', title: '@Html.Raw(titulo)' },
{
extend: 'pdfHtml5', title: '@Html.Raw(titulo)',
//orientation: 'landscape',
pageSize: 'LEGAL',
exportOptions: {
columns: [0, 1]
}
},
{
extend: 'print',
customize: function (win) {
$(win.document.body).addClass('white-bg');
$(win.document.body).css('font-size', '10px');
$(win.document.body).find('table').addClass('compact').css('font-size', 'inherit');
$(win.document.body).find('table').find('th:last-child').remove();
$(win.document.body).find('table').find('td:last-child').remove();
}
}
],
aoColumnDefs: [
{ bSortable: false, aTargets: [-1] },
{ bSearchable: false, aTargets: [-1] },
{
mRender: function (data, type, row) {
var id = data;
var html = "<div class='ibox-tools'>";
html += "<a class='dropdown-toggle' data-toggle='dropdown' href='#' aria-expanded='false'><i class='fa fa-ellipsis-h'></i></a><ul class='dropdown-menu dropdown-user'>";
html += "<li><a href='/@controller/Details/" + id + "' title='Visualizar' class='detalhes @classDetails'> Visualizar</a></li>";
html += "<li><a href='/@controller/Edit/" + id + "?&ex=1' title='Alterar' class='alterar @classEdit'> Alterar</a></li>";
html += "<li><a href='javascript:;' title='Deletar' class='deletar @classDel' data-rel='" + id + "," + row[0].replace(",", "") + ",@controller,Del'> Deletar</a></li>";
html += "</ul></div>";
return html;
},
aTargets: [-1]
}
],
fnRowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$(nRow).attr("id", aData[aData.length - 1]);
return nRow;
}
});