caim Posted January 19, 2016 Share Posted January 19, 2016 Hello, Having some issues with this Given http://codepen.io/caim/pen/pggZOx I'm trying to replace the first column from input to select dropdown but having trouble figuring out how to read the data for each cell. It was working fine with an input and normal td but now the select entered the picture and it's skipping one column. The day drop-downs are for newly added rows currently. This is how I'm trying to read the data, maybe I'm missing something essential here $BTN.click(function () { var $rows = $TABLE.find('tr:not(:hidden)'); var $tds = $TABLE.find('td:not(:hidden)'); var headers = []; var data = []; // Get the headers (add special header logic here) $($rows.shift()).find('th:not(:empty)').each(function () { headers.push($(this).text().toLowerCase()); }); // Turn all existing rows into a loopable array $rows.each(function () { var $td = $(this).find('td'); var $td2 = $td.find('input'); var $td3 = $td.find('select'); var h2 = {}; // Use the headers from earlier to name our hash keys headers.forEach(function (header, i) { // h2[header] = $td.eq(i).text(); //the dropdown value -> //console.log($td3.eq(i).val()); h2[header] = $td3.eq(i).val(); if ($td3.eq(i).val() === undefined){ // it's not dropdown ? read it normaly.. console.log(i); h2[header] = ($td.eq(i).text() == '') ? $td2.eq(i).val() : $td.eq(i).text(); } //console.log(h2[header]); }); data.push(h2); }); // Output the result $EXPORT.text(JSON.stringify(data)); }); Link to comment Share on other sites More sharing options...
dsonesuk Posted January 19, 2016 Share Posted January 19, 2016 You have selector value for table id referencing class name var $TABLE = $('#table'); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now