Skip to content

Instantly share code, notes, and snippets.

@breizhwave
Last active January 11, 2021 15:34
Show Gist options
  • Save breizhwave/545a361ed941d7b449e7a9a07bf97055 to your computer and use it in GitHub Desktop.
Save breizhwave/545a361ed941d7b449e7a9a07bf97055 to your computer and use it in GitHub Desktop.
add sum in list blade
<script>
// Insert the sum of a column into the columns footer, for the visible
// data on each draw
// var table = $('#crudTable').DataTable();
// $("#wave_total").html( $('#crudTable').column( 3 ).data().sum());
jQuery(document).ready(function($) {
jQuery.fn.dataTable.Api.register( 'sum()', function ( ) {
return this.flatten().reduce( function ( a, b ) {
if ( typeof a === 'string' ) {
a = a.replace(/[^\d.-]/g, '') * 1;
}
if ( typeof b === 'string' ) {
b = b.replace(/[^\d.-]/g, '') * 1;
}
return a + b;
}, 0 );
} );
// var table = $('#crudTable').DataTable();
crud.table.on('draw.dt', function () {
// console.log('Redraw occurred at: ' + new Date().getTime());
$("#waveTotal").html(crud.table.column(6).data().sum() );
});
});
</script>
<div id="waveTotal"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment