I have a jquery datatable that contains name and count data.
<tr>
<th>Name</th>
<th class="count">Count</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class= "name"><%# Eval("Name") %></td>
<td class= "count"><%# Eval("count") %></td>
</tr>
The issue i am facing is trying to retrieve data that matches a certain criteria based on 2 selectors. For instance, how would i write a jquery function to retrieve names that are “john” and have a count of 4? I am able to retrieve positions where all names that are john as follows:
$('td').each(function () {
var aPos = oTable.fnGetPosition(this);
var aData = oTable.fnGetData(aPos[0]);
var retrievedEntry = aData[aPos[1]];
if (retrievedEntry == "john") {
alert($(this).html() + "found at position " + aPos);
}
});
I tried alert($(this).find(".count").filter(":contains("1")")); as a test but keep getting null values.
Also once the data is retrieved, how would i delete all the duplicates and jus leave one record? Your help is much appreciated.
You can get the cells that contain “john”, and then filter that result to only contain the ones that have “4” in the next element:
Note: The
:containsselector makes a partial match, so it would also match for example “johnny”. If that is a problem, you would put that check in the filter also: