gundambison

perbaikan 65

Jun 9th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     $(document).ready(function () {
  3.         var table = $('#demo-form2').DataTable({
  4.             "footerCallback": function (row, data, start, end, display) {
  5.                 var api = this.api(), data;
  6.  
  7.                 //Remove the formatting to get integer data for summation
  8.                 var intVal = function (i) {
  9.  
  10.                     if (typeof i === 'string') {
  11. /***
  12. ubah
  13. , => ;
  14. . => null
  15. ; => .
  16.  
  17. default angka
  18. . => desimal
  19. ***/
  20.                         //console.log(i);
  21.                         res=i.replace(/\,/g, ';');
  22.                         //console.log(res);
  23.                         res=res.replace(/\./g, '');
  24.                         //console.log(res);
  25.                         res=res.replace(/\;/g, '.');
  26.                         //console.log(res);
  27.                         /*
  28.                         res = i.replace(".", " ");
  29.                        
  30.                         res = res.replace(",", ".");
  31.                         console.log(res);
  32.                         res = res.replace(" ", "");
  33.                         console.log(res);
  34.             */
  35.  
  36.                     } else if (typeof i === 'number') {
  37.                         res = i;
  38.                     } else {
  39.                         res = 0;
  40.                     }
  41.                     return res;
  42.  
  43.                     /*
  44.               //-------------------------jangan dipake lagi=====================      
  45.                      return typeof i === 'string' ?
  46.                      i.replace('.', '').replace(/[\$,]/g, '.')  :
  47.                      typeof i === 'number' ?
  48.                      i : 0;
  49.                      */
  50.                 };
  51.  
  52.                 //Total over all pages
  53.                 total = api
  54.                         .column(5)
  55.                         .data()
  56.                         .reduce(function (a, b) {
  57.                             //console.log(a, b);
  58.                             a1 = parseFloat(intVal(a));
  59.                             b1 = parseFloat(intVal(b));
  60.                             //console.log(a1, b1);
  61.                             return a1 + b1;//parseFloat(intVal(a)) + parseFloat(intVal(b))
  62.                         }, 0);
  63.  
  64.                 //Total over this page
  65.                 pageTotal = api
  66.                         .column(5, {page: 'current'})
  67.                         .data()
  68.                         .reduce(function (a, b) {
  69.                             a1 = parseFloat(intVal(a));
  70.                             b1 = parseFloat(intVal(b));
  71.                             //console.log(a1, b1);
  72.                             return a1 + b1;
  73.                         }, 0);
  74.  
  75.                 //Update footer
  76.                 $(api.column(5).footer()).html(
  77.                         'total ' + formatThousands(pageTotal.toFixed(2),2) + '<br/> ( Rp ' +
  78.                         formatThousands(total.toFixed(2),2) + ' total)'
  79.                         );//
  80.             },
  81.             "language": {
  82.                 url: 'assets/global/plugins/DataTables-1.10.12/DataTables/Polish.json',
  83.                 "decimal": ",",
  84.                 "thousands": ".",
  85.                 buttons: {
  86.                     copyTitle: 'Kopiowanie danych',
  87.                     copySuccess: {
  88.                         _: 'Skopiowano %d wierszy',
  89.                         1: 'Skopiowano 1 wiersz'
  90.                     }
  91.                 }
  92.             },
  93.         });
  94.     });
  95. //https://stackoverflow.com/questions/5731193/how-do-i-format-numbers-using-javascript
  96. var formatThousands = function(n, dp){
  97.   var s = ''+(Math.floor(n)), d = n % 1, i = s.length, r = '';
  98.   while ( (i -= 3) > 0 ) {
  99.       r = '.' + s.substr(i, 3) + r;
  100.   }
  101.   return s.substr(0, i + 3) + r +
  102.     (d ? ',' + Math.round(d * Math.pow(10, dp || 2)) : ',00');
  103. };
Advertisement
Add Comment
Please, Sign In to add comment