1
I searched here on Stak and online, 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 little different because I’m using Jquery Bootgrid and all the materials I read end up not working.
As I have a filter in the bootgrid and already have the data filtered on the screen, I need to export this data to Excel. As I have seen, some programmers recommend transforming the HTML table to excel.
I’ve used Jquery.table2excel, also tried tableexport, but none worked. My bootgrid is simple, and still can’t export excel from it. The closest I got was with 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>
}
I believe that bootgrid does not have this transformation to excel natively. At least as far as I’ve seen in his documentation I haven’t seen anything about it, one that I know has this natively is the datagrid
– gabrielfalieri
you could provide the way you implemented the filter?
– Leila