Match cell text in table and count the unique values
JQuery to find table cells containing the same data and counting them as groups. ~ andrew pougher
by Andrew Pougher
HTML
<table>
<tr><td>BA33</td><td>Dave</td><td></td></tr>
<tr><td>VS12</td><td>Sam</td><td></td></tr>
<tr><td>BA33</td><td>Claire</td><td></td></tr>
<tr><td>BA33</td><td>Andrew</td><td></td></tr>
<tr><td>VS12</td><td>Emma</td><td></td></tr>
<tr><td>AA11</td><td>Julianna</td><td></td></tr>
<tr><td>AA11</td><td>Liz</td><td></td></tr>
<tr><td>AA11</td><td>Shaun</td><td></td></tr>
<tr><td>AA11</td><td>Michele</td><td></td></tr>
<tr><td>AF1</td><td>John F</td><td></td></tr>
</table>
CSS
body{padding:40px}
span.groupttl{
font:10px arial;
background:#cc1100;
height: 12px;
text-align:center;
width: 12px;
text-indent:none;
border:2px solid #fff;
color:#fff;
display:block;
position:absolute;
margin-top:-2px;
-moz-border-radius: 35px;
border-radius: 35px;
;text-shadow:1px 1px rgba(000, 000, 000, 0.5);
-webkit-box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, .4);
box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, .4);
}
td {width:90px; text-align:right;}
table{border:1px solid #ccc}
JavaScript
/*========================================
identify matches in table and count them
==========================================*/
$("table tr td:first-child").each(function(){
if($(this).parent().length)
$("td:contains('" + $(this).html() + "')").not(this).css("color","red");
var ddd = $("td:contains('" + $(this).html() + "')").length;
$(this).prepend("<span class='groupttl'>" + ddd + "</span>")
});