Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function generateReport() {
- let bodyRowsRef = document.querySelectorAll("tbody tr");
- let headRowsRef = document.querySelectorAll("thead tr th input");
- let columnPosition = [];
- for (let index = 0; index < headRowsRef.length; index++) {
- if ( headRowsRef[index].checked == true){
- columnPosition.push(index);
- }
- }
- let finalResult = [];
- // let data = document.querySelectorAll("tbody tr");
- for (let j = 0; j < bodyRowsRef.length; j ++) {
- let currRow = bodyRowsRef[j].children;
- let currItems = {};
- for (let k = 0; k < currRow.length; k ++) {
- if (columnPosition.includes(k)) {
- let label = headRowsRef[k].name;
- currItems[label] = currRow[k].textContent;
- }
- }
- finalResult.push(currItems);
- }
- let jsonFinal = JSON.stringify(finalResult);
- let target = document.getElementById('output');
- target.value = jsonFinal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement