jquery - Sum red row of a table in javascript and then alter the table -


my web application collects data with:

  • id (key value)

  • timestamp

  • value

then, creates html table this:

<table>   <tr bgcolor="#ffa9a9">     <td> id1 </td>       <td> 20150619t09.43.03</td>      <td>value1</td>    </tr>   <tr>       <td> id2 </td>     <td> 20150619t09.43.02</td>      <td>value1</td>    </tr>   <tr bgcolor="#ffa9a9">       <td> id3 </td>     <td> 20150619t09.43.00</td>      <td>value2</td>    </tr>   <tr>       <td> id4 </td>     <td> 20150619t09.42.59 </td>      <td> value1</td>    </tr>   <tr bgcolor="#ffa9a9">       <td> id5 </td>     <td> 20150619t09.42.59 </td>      <td> value2</td>    </tr>   <tr>       <td> id6 </td>     <td> 20150619t09.42.58</td>      <td>value2</td>    </tr>   <tr>       <td> id7 </td>     <td> 20150619t09.42.55 </td>      <td> value2 </td>    </tr>   <tr bgcolor="#ffa9a9">       <td> id8 </td>     <td> 20150619t09.42.40 </td>      <td> value2 </td>    </tr>   <tr>       <td> id9 </td>     <td> 20150619t09.42.39 </td>      <td> value2 </td>    </tr> </table> 

explanation: sorts timestamp value in desc order.

if, example, t1 timestamp id1 , 't2' timestamp id2, and...

t1 + 2 seconds >= t2

the id2 row becomes red.

in example:

  • id1 red (#ffa9a9) cause of id2 (same value , timestamp between 2 sec)

  • id3 red cause of id5 red cause of id6.

  • id8 red cause of id9

in case id1 copy , id2 original; id3 , id5 copy , id6 original; id8 copy , id9 it's original.

i've got count red copy , put counter in cell of row original.

the result of example should be:

<table>   <tr>       <td> id2 </td>     <td> 20150619t09.43.02</td>      <td>value1</td>      <td>1</td>    --> 1 record not shown (id1)   </tr>    <tr>       <td> id4 </td>     <td> 20150619t09.42.59 </td>      <td> value1</td>      <td> 0 </td>   </tr>    <tr>       <td> id6 </td>     <td> 20150619t09.42.58</td>      <td>value2</td>      <td>2</td>    --> 2 records not shown (id3 , id5)   </tr>   <tr>       <td> id7 </td>     <td> 20150619t09.42.55 </td>      <td> value2 </td>      <td> 0 </td>   </tr>   <tr>       <td> id9 </td>     <td> 20150619t09.42.55 </td>      <td> value2 </td>      <td> 1 </td>    --> 1 record not shown (id8)   </tr> </table> 

i need because i've got 3 data collector , need understand event same 1 repeated... if value same , timestamp between 2 sec same event , need take older 1 in table need show exists other captured copy of it...

any help? can change class, name or else, need when html page loaded , client side (so javascript or jquery)...

i need to:

1) scan table row row first last

2) understand if red row

3) if red row need start count of red rows same value before row not red same value. put counter in new cell of same not red row...

thank much!!! (and sorry bad english!)

with jquery can select tr elements attribute bgcolor="#ffa9a9" use .size() or .length count.

jquery('tr[bgcolor="#ffa9a9"]').size(); 

api.jquery.com/attribute-equals-selector

hope useful.

edit: red lines selected above can run .each() on selected elements , analyse .children()

edit 2: maybe useful approach?

trs = jquery('tr:not[bgcolor="#ffa9a9"]'); redtrs = jquery('tr[bgcolor="#ffa9a9"]');  (i in trs) {     tds = trs.eq(i).children('td');     (j in redtrs)     {         redtds = redtrs.eq(j).children('td');         //do checking here     } } 

the idea select trs not red , trs red. iterate on non-red trs , check children tds against red trs children tds (assuming order of tds same). tds.eq(0) id, tds.eq(1) time stamp tds.eq(2) value. can compare tds.eq(2) == redtds.eq(2) match values. when have find counter , end adding fourth td counter value. try reading in on jquery selectors , javascript in loop (or jquery.each can bit more confusing beginners though).


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -