Advertisement
Virajsinh

Footer Calculation Total Row in HTML using Java Script With DataTable

Mar 9th, 2024 (edited)
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.67 KB | Source Code | 0 0
  1. let noOfRow = $('#ajaxSalarytable tbody tr').length - 1; // Total No Of Row
  2. let range_td_total = arrayRange(5, 45, 1); // Range Start From 5 To 45. Array
  3. var calculationArray = [];
  4.  
  5. // 5 is Start Calculation from Column Index
  6. for (var j = 5; j < range_td_total.length; j++)
  7. {
  8.     this["value"+j] = 0.00;
  9.     // console.log('===  index.js [196] ===', this["value"+j]);
  10.     for(var i = 0; i < noOfRow; i++)
  11.     {
  12.         // console.log('===  index.js [199] ===', this["value"+j]);
  13.         this["temp_value"+j] = $('#ajaxSalarytable tbody tr').eq(i).find("td").eq(j).html();
  14.         // console.log('===  index.js [201] ===', this["temp_value"+j]);
  15.         // console.log('===  index.js [202] ===', $('#ajaxSalarytable tbody tr').eq(i).find("td").eq(j));
  16.         this["value"+j] = parseFloat(this["temp_value"+j]) + parseFloat(this["value"+j]);
  17.         this["value"+j] = this["value"+j].toFixed(2); // working_hrs
  18.     }
  19.     calculationArray.push(this["value"+j]);
  20.     // console.log('===  index.js [206] ===', this["value"+j]);
  21. }
  22. // console.log('===  index.js [209] ===', calculationArray);
  23.  
  24. c_index = 0; // Total Row Cell Start From 0 Index
  25. var TotalNotShowCols = [32, 34]; // Add Column Index To Remove From Total Row
  26. for (var i = 1; i < calculationArray.length; i++)
  27. {
  28.     if(!isInArray(c_index, TotalNotShowCols)){
  29.         $('#ajaxSalarytable tbody tr').eq(4).find("th").eq(i).text(calculationArray[c_index]);
  30.     }
  31.     c_index = c_index + 1;
  32. }
  33.  
  34. const arrayRange = (start, stop, step) =>
  35.     Array.from(
  36.       { length: (stop - start) / step + 1 },
  37.       (value, index) => start + index * step
  38.     );
  39.  
  40. function isInArray(value, array) {
  41.   return array.indexOf(value) > -1;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement