I have researched here in the stak and the internet, and I have seen some articles and tips on how to export an HTML table to excel. But in my case, I think it's a bit different because I'm using JQuery Bootgrid and all the materials I read end up not working.
As I have a bootgrid filter and I already have the filtered data on the screen, I need to export this data to Excel. As I've seen, some programmers recommend converting the HTML table to excel.
I've already used Jquery.table2excel, I also tried the tableexport, but none worked. My bootgrid is simple, and even then it can not export excel from it. What I got closer was with the tableexport, but the file is generated empty.
Follow my code, I'm using ASP.NET MVC with bootgrid.
@{
ViewBag.Title = "Lista - Certificados Digitais";
}
<body>
<p>
<a href="#" class="btn btn-success" data-action="Create">
<span class="glyphicon glyphicon-plus"></span>
Cadastrar
</a>
</p>
<table id="gridCertificados">
<thead>
<tr>
<th data-column-id="CertificadoChave">Chave</th>
<th data-column-id="CertificadoDescricao">Descrição</th>
<th data-column-id="TipoCertificadoNome">Tipo</th>
<th data-column-id="ModeloCertificadoNome">Modelo</th>
<th data-column-id="FornecedorNome">Fornecedor</th>
<th data-column-id="CertificadoPreco">Preço</th>
<th data-column-id="CertificadoDtVencimento" data-order="asc">Vencto.</th>
<th data-formatter="acoes" data-sortable="false">Ações</th>
</tr>
</thead>
</table>
<button id="btn" class="btn btn-success">Exportar Excel</button>
<div class="modal fade" id="minhaModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg role=" document"">
<div class="modal-content">
<div class="modal-body">
<div id="conteudoModal"></div>
</div>
</div>
</div>
</div>
</body>
@section scripts
{
@Scripts.Render("~/bundles/jqueryval")
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/jquery.table2excel.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/jquery.bootgrid.js"></script>
<script src="~/Scripts/Projeto/ControlarGrid.js"></script>
<script type="text/javascript">
var controller = "Certificados";
var urlListar = "@Url.Action("Listar")"
$(document).ready(configurarControles);
$("#btn").click(function () {
$("#gridCertificados").table2excel({
name: "Certificados",
filename: "certif"
});
});
</script>
}