Alterar de Lugar o resultado dataTable
14/06/2023
0
<!-- Datatables JS-->
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.js"></script>
<!-- SUM() Datatables-->
<script src="https://cdn.datatables.net/plug-ins/1.10.20/api/sum().js"></script>
<script type="text/javascript" class="init">
$(document).ready(function(){
var tabla = $("#example").DataTable({
"createdRow":function(row,data,index){
//pintar una celda
if(data[4] >= 1000){
/* $('td', row).eq(5).css({
'background-color':'#ff5252',
'color':'white',
}); */
//pintar una fila
$('td', row).css({
'background-color':'#ff5252',
'color':'white',
'border-style':'solid',
'border-color':'#bdbdbd'
});
}
},
"drawCallback":function(){
//alert("La tabla se está recargando");
var api = this.api();
$(api.column(4).footer()).html(
'Total: '+api.column(4, {page:'current'}).data().sum().toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' })
)
}
});
//1era forma para sum()
//var tot = tabla.column(5).data().sum();
//$("#total").text(tot);
});
</script>
Willian Silva
Post mais votado
15/06/2023
<div id=novototal style=text-align:right></div> <table id="example" class="display" style="width:100%">
2) e mudar o código JavaScript de
$(api.column(4).footer()).html('$' + pageTotal + ' ( $' + total + ' total)');
para
$('#novototal').html('Novo Total $' + pageTotal + ' ( $' + total + ' total)');
Frank Hosaka
Mais Posts
14/06/2023
Frank Hosaka
<input id=total> <table id="example"><thead><tr><th><th></thead> <tbody> <tr><td>joao<td>1 <tr><td>pedro<td>2 </tbody> </table> <script src="https://code.jquery.com/jquery-3.7.0.slim.min.js"></script> <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script> <script> $(document).ready(function () { $('#example').DataTable(); $('#total').val("Meu nome é Frank"); }); </script>
14/06/2023
Willian Silva
https://datatables.net/examples/advanced_init/footer_callback.html
15/06/2023
Willian Silva
Clique aqui para fazer login e interagir na Comunidade :)