Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- var table = $('#demo-form2').DataTable({
- "footerCallback": function (row, data, start, end, display) {
- var api = this.api(), data;
- //Remove the formatting to get integer data for summation
- var intVal = function (i) {
- if (typeof i === 'string') {
- /***
- ubah
- , => ;
- . => null
- ; => .
- default angka
- . => desimal
- ***/
- //console.log(i);
- res=i.replace(/\,/g, ';');
- //console.log(res);
- res=res.replace(/\./g, '');
- //console.log(res);
- res=res.replace(/\;/g, '.');
- //console.log(res);
- /*
- res = i.replace(".", " ");
- res = res.replace(",", ".");
- console.log(res);
- res = res.replace(" ", "");
- console.log(res);
- */
- } else if (typeof i === 'number') {
- res = i;
- } else {
- res = 0;
- }
- return res;
- /*
- //-------------------------jangan dipake lagi=====================
- return typeof i === 'string' ?
- i.replace('.', '').replace(/[\$,]/g, '.') :
- typeof i === 'number' ?
- i : 0;
- */
- };
- //Total over all pages
- total = api
- .column(5)
- .data()
- .reduce(function (a, b) {
- //console.log(a, b);
- a1 = parseFloat(intVal(a));
- b1 = parseFloat(intVal(b));
- //console.log(a1, b1);
- return a1 + b1;//parseFloat(intVal(a)) + parseFloat(intVal(b))
- }, 0);
- //Total over this page
- pageTotal = api
- .column(5, {page: 'current'})
- .data()
- .reduce(function (a, b) {
- a1 = parseFloat(intVal(a));
- b1 = parseFloat(intVal(b));
- //console.log(a1, b1);
- return a1 + b1;
- }, 0);
- //Update footer
- $(api.column(5).footer()).html(
- 'total ' + formatThousands(pageTotal.toFixed(2),2) + '<br/> ( Rp ' +
- formatThousands(total.toFixed(2),2) + ' total)'
- );//
- },
- "language": {
- url: 'assets/global/plugins/DataTables-1.10.12/DataTables/Polish.json',
- "decimal": ",",
- "thousands": ".",
- buttons: {
- copyTitle: 'Kopiowanie danych',
- copySuccess: {
- _: 'Skopiowano %d wierszy',
- 1: 'Skopiowano 1 wiersz'
- }
- }
- },
- });
- });
- //https://stackoverflow.com/questions/5731193/how-do-i-format-numbers-using-javascript
- var formatThousands = function(n, dp){
- var s = ''+(Math.floor(n)), d = n % 1, i = s.length, r = '';
- while ( (i -= 3) > 0 ) {
- r = '.' + s.substr(i, 3) + r;
- }
- return s.substr(0, i + 3) + r +
- (d ? ',' + Math.round(d * Math.pow(10, dp || 2)) : ',00');
- };
Advertisement
Add Comment
Please, Sign In to add comment