jquery - Javascript summarize duplicate and unique enteries of table -
i have table 1 has following data right can up-to 50-100 rows. want summarize information in on summarize button click , want show in other table created on fly according summarized information. don't know how it.
i want if code exists more once in output table of sq-in should added up. in above table a1 repeated 3 times sqin added , gives a1 81. right id's of code's textbox #code_0, #code_1,#code_2 , on. sqin #sqin_0, #sqin_1, #sqin_2 , on...
<table id="mytable"> <thead> <tr> <th>codes</th> <th>room</th> <th>sqin</th> </tr> </thead> <tbody> <tr> <td><input type="text" value="a1" /></td> <td><input type="text" value="1" /></td> <td><input type="text" value="25"/></td> </tr> <tr> <td><input type="text" value="b1" /></td> <td><input type="text" value="1"/></td> <td><input type="text" value="25"/></td> </tr> <tr> <td><input type="text" value="c1" /></td> <td><input type="text" value="1"/></td> <td><input type="text" value="25"/></td> </tr> <tr> <td><input type="text" value="a1" /></td> <td><input type="text" value="2"/></td> <td><input type="text" value="25"/></td> </tr> <tr> <td><input type="text" value="b1" /></td> <td><input type="text" value="1"/></td> <td><input type="text" value="25"/></td> </tr> <tr> <td><input type="text" value="c1"/></td> <td><input type="text" value="2"/></td> <td><input type="text" value="25"/></td> </tr> </tbody> </table> <button id=summarise ">summarise</button> <table id="summarizedtable"> //here summary table should come. </table>
js
sqin: +(element.childnodes[1].firstelementchild.value)
in close psuedo code form, below:
var mylist = {}; $('input[id^="code"]').each(function(){ // grab input id begins 'code' var myid = $(this).attr("id"); // actual id if( mylist[myid] == '' ){ var value = 0; $('input').find('[id=' + myid + ']').each(function(){ value += $(this).next().val(); // elements next 'id=myid' }); mylist[myid] = value; // insert total } }); for( var in mylist ){ var id = i; var value = mylist[i]; // draw summary <td> using id , value here }
Comments
Post a Comment