dunyto

Create Report

Jun 1st, 2022
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function generateReport() {
  2.     let cbs = document.querySelectorAll("thead tr th input");
  3.     let colPos = [];
  4.     for (let i = 0; i < cbs.length; i ++) {
  5.         if (cbs[i].checked) {
  6.             colPos.push(i);
  7.         }
  8.     }
  9.  
  10.     let finalResult = [];
  11.  
  12.     let data = document.querySelectorAll("tbody tr");
  13.     for (let j = 0; j < data.length; j ++) {
  14.         let currRow = data[j].children;
  15.         let currItems = {};
  16.         for (let k = 0; k < currRow.length; k ++) {
  17.             if (colPos.includes(k)) {
  18.                 let label = cbs[k].name;
  19.                 currItems[label] = currRow[k].textContent;
  20.             }
  21.         }
  22.         finalResult.push(currItems);
  23.     }
  24.  
  25.     let jsonFinal = JSON.stringify(finalResult);
  26.     let target = document.getElementById('output');
  27.     target.value = jsonFinal;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment