Data matching with jquery -


i have values find , match on data table. http://jsfiddle.net/hhkd4ygu/ can see, there 3 values , if groups of 3 values present altogether on given row of data table, next row (present) should highlighted; green present, red color not present.

note: 3 values should present on row , values may not in adjacent cells.

i've been trying solve problem on excel , did of code obtained vba forum here. realized running vba code large data set extremely slow , freezing computer.

so created simple table exemplify i've been working on.

.table.table {  	border: 1px solid #ccc; font-family: arial, helvetica, sans-serif;  	font-size: 12px;  	text-align: center;  	  }   .table td {  	padding: 4px;  	margin: 3px;  	border: 1px solid #ccc;  	width: 40px;  }  .table th {  	background-color: #e99d79;   	color: #fff;  	font-weight: bold;  }    .yes {  background: green;  }    .no {  background: red;  }   
<table class="table">  <tr class="firstrow">  <th colspan="3">values find</th>  <th>&nbsp;</th><th> presence</th>  <th>&nbsp;</th>  <th colspan="4">data table</th></tr>     <tr><td>1</td><td>12</td><td>13</td><td>&nbsp;</td><td class="yes"> </td><td>&nbsp;</td><td>f</td><td>g</td><td>d</td><td>2</td></tr>   <tr><td>4</td><td>5</td><td>6</td><td>&nbsp;</td><td class="yes">&nbsp;</td><td>&nbsp;</td><td>1</td><td>12</td><td>g</td><td>13</td></tr>   <tr><td>a</td><td>b </td><td>c</td><td>&nbsp;</td><td class="yes">&nbsp;</td><td>&nbsp;</td><td>a</td><td>b</td><td>c</td><td>6</td></tr>   <tr><td>d</td><td>e</td><td>f</td><td>&nbsp;</td><td class="no">&nbsp;</td><td>&nbsp;</td><td>4</td><td>2</td><td>5</td><td>6</td></tr>   <tr><td>3</td><td>10</td><td>b</td><td>&nbsp;</td><td class="no">&nbsp;</td><td>&nbsp;</td><td>3</td><td>10</td><td>f</td><td>k</td></tr>   <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>   <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td></td></tr>  </table>

-------------------edited after answer provided below---

for future reference, kind of work, in addition this, may want check excel+vba solution (which slow)=> matching multiple cell values on table, , excel solution => matching 3 values (three cells) on table (see last comment).

take @ following solution:

http://jsfiddle.net/hhkd4ygu/3/

in example given, acts if a, b, c present too. however, considering "not adjacent" criterium:

  • if want triples present when found not adjacent, code below fine
  • if don't care wether found triples adjacent, remove && (max-min >= 3) part in return statement of match function.

code:

var trs = $('table').find('tr')  var gethtml = function () {         return $(this).html()     } var rows = []; trs.each(function () {     var values = $(this).find('td').slice(6).map(gethtml).get();     rows.push(values); });  var match = function(row) {     var ids = this.map(function(v){         return row.indexof(v);     })     var min = math.min.apply(null,ids);     var max = math.max.apply(null,ids);     return (min > -1) && (max-min >= 3); }  trs.each(function () {     var tds = $(this).find('td').slice(0,3);     var values = $(this).find('td').slice(0,3).map(gethtml).get();      var output = $(this).find('td').eq(4);     var ismatch = rows.some(match.bind(values));     output.addclass(ismatch ? 'yes' : 'no'); }); 

i can comment how works if like.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -