$(document).ready( function(){ var newVal = ''; var authorVal = ''; var publishVal = ''; // var pushObj = [{ // "id": "", // "tableName": "", // "tableKey": "", // "columnName": "", // "new": "", // "author": "", // "publish": "" // }] // var pushObj = [] // console.log("Initial Val= " + newVal, authorVal, publishVal); // load data loadData(); getSelectedVal(); }); // initial load get all data from getmanualapprovals function loadData(){ var dataUrl = './data/data.json'; // var dataUrl = 'http://dit-msapi001.ad.tiaa-cref.org:8080/api/v1/mic/getmanualapprovals'; $.getJSON(dataUrl, function (data) { var dynamicTabledata = ''; // ITERATING THROUGH OBJECTS $.each(data, function (key, value, i) { console.log(value); if ( Array.isArray(value.new) || Array.isArray(value.author) || Array.isArray(value.publish)){ newVal = value.new.join("|"); authorVal = value.author.join("|"); publishVal = value.publish.join("|"); } else { newVal = value.new; authorVal = value.author; publishVal = value.publish; } // console.log("After Load Val= " + newVal, authorVal, publishVal); // DATA FROM JSON OBJECT dynamicTabledata += ''; // dynamicTabledata += ''; dynamicTabledata += ` `; dynamicTabledata += '' + value.tableName + ''; dynamicTabledata += '' + value.tableKey + ''; dynamicTabledata += '' + value.columnName + ''; dynamicTabledata += '' + newVal + ''; dynamicTabledata += '' + authorVal + ''; dynamicTabledata += ''; }); //INSERTING ROWS INTO TABLE BODY $('#dynamic-table-data').append(dynamicTabledata); }); }; function getSelectedVal() { $(document).on('change', '.selectApprove', function(e){ var getParentRowId = $(this).parent().parent().attr("data-id"); var getSelectedDropDownId = $(this).attr("id"); // console.log("getParentRowId: ", getParentRowId) // console.log("getSelectedDropDownId: ", getSelectedDropDownId) // console.log(e.target.value); if(getParentRowId === getSelectedDropDownId){ $(`[data-id='${getParentRowId}'] .setDropVal`).html(e.target.value); // $(`[data-id='${getParentRowId}']`).attr(`[data-item]="${e.target.value}"`); } }); } function approveChangeBtn(){ let $rows = $('#dynamic-table-data').find('tr'), headers = $rows.splice(0, 1); // header rows let formatMe = ($el) => $el.text().trim() // iterate rows to get the table info $rows.each((i, row) => { let $cols = $(row).find('td'); let tpl = []; // within each row, lets get the name and the details let pushObj = []; // tpl.push({ // "id" : formatMe($cols), // "tableName" : formatMe($cols), // "tableKey" : formatMe($cols), // "columnName" : formatMe($cols), // "new" : formatMe($cols), // "author" : formatMe($cols), // "publish" : formatMe($cols), // }); // pushObj.push(tpl) $cols.each((i, col) => { let $col = $(col); // console.log("length: ", $col.length) // tpl.push(formatMe($col)); // if ($col.prop('id') == ROW_NAME_KEY) { // tpl['id'] = formatMe($col); // return; // } // pushObj.push({ // "id" : $col.text(), // "tableName" : $col, // "tableKey" : $col, // "columnName" : $col, // "new" : $col, // "author" : $col, // "publish" : $col, // }); tpl.push({ "id" : formatMe($col), "tableName" : formatMe($col), "tableKey" : formatMe($col), "columnName" : formatMe($col), "new" : formatMe($col), "author" : formatMe($col), "publish" : formatMe($col), }); pushObj.push(tpl) }); console.log(pushObj); // pushObj.push("Hello"); }) }