javascript - Jquery - check column checkboxes then do something with those rows -
i've been trying find match question, nothing concrete. i'm still learning , don't know i'm missing.
so code can found here: fiddle
this simplified version of i'm working with. in final version, upload csv file html table see there (id="dvcsv"). upon uploading, table shown (with added dropdowns , column of checkboxes). checkboxes come "pre-chcecked" when generate them want user able turn "off" rows not want calculate on.
i'll run through process: function reads columns user designates. don't know column upload data into.
function checklocations() { //checks uploaded data locations of lat/lon data based on user dropdowns collocs[0] = ($('#value_0 :selected').text()); collocs[1] = ($('#value_1 :selected').text()); collocs[2] = ($('#value_2 :selected').text()); collocs[3] = ($('#value_3 :selected').text()); latcolumn = collocs.indexof("lat"); longcolumn = collocs.indexof("long"); } function allthesame(array) { //if not designate checkboxes, prompt them var first = array[0]; return array.every(function (element) { return element === first; }); }
this function takes of data in designated columns , places them array calculation.
function data2array() { //gets lat , long data assigned columns , transfers them array calculation $("#dvcsv tr td:nth-child(" + (latcolumn + 1) + ")").each(function () { var tdnode = $("<td/>"); tdnode.html(this.innerhtml); latdata.push(tdnode.text()); }); latdata.splice(0, 2); latdata.unshift(1, 1); $("#dvcsv tr td:nth-child(" + (longcolumn + 1) + ")").each(function () { var tdnode = $("<td/>"); tdnode.html(this.innerhtml); longdata.push(tdnode.text()); }); longdata.splice(0, 2); //these 2 lines remove first 2 items replace them 0 longdata.unshift(1, 1); }
the first of these functions removes checkbox column after calculations done new calculated columns appended @ end. second 1 attempt read checkboxes array. ideally i'd want array of values true or false, calculations , return calculated values dvcsv table. td's no calculation performed, cell empty.
function removechecks() { $("#dvcsv th:last-child, #dvcsv td:last-child").remove(); } function makecheckarray() { var searchids = $("#dvcsv tbody td:last() input:checkbox:checked").map(function () { return $(this).val(); }).get(); alert(searchids); }
hopefully made problem clear. appreciated.
pass class when table generated tr element. create on change method checkboxes. read more here: http://api.jquery.com/on/
also if cannot inserted rows id's table start counter outside of js this
counter = 0;
then inside of loop add counter++
so..
<tr class="row-1"> <td> </td> </tr>
then add snippet outside of other js
$( "tr" ).on( "change", function() { //do $(this+'.row-'+(counter)).hide(); });
this should headed in right direction.
Comments
Post a Comment