Table row example
Need to search on "Pf Id" column. The Portfolio ID is defined as class="td_pfid" in each <TD>.
by bob m
HTML
<table id="pftable">
<thead>
<tr style="background-color: rgb(211, 220, 224);">
<th> Pf Id </th>
<th> Name </th>
<th> Exp Type </th>
<th> Date </th>
<th> Term </th>
<th> Exposure </th>
</tr>
</thead>
<tbody>
<tr>
<td class="td_pfid">
1726
</td>
<td width="120">
ABC CA Cash
</td>
<td>
Historical VaR
</td>
<td class="td_nodedate">
01/19/2012
</td>
<td>
1D 99
</td>
<td align="right">
19,010.56
</td>
</tr>
<tr style="background-color: rgb(211, 220, 224);">
<td class="td_pfid">
1726
</td>
<td width="120">
ABC CA Cash
</td>
<td>
Historical VaR
</td>
<td class="td_nodedate">
01/20/2012
</td>
<td>
1D Mean
</td>
<td align="right">
73.84
</td>
</tr>
<tr>
<td class="td_pfid">
1726
</td>
<td width="120">
ABC CA Cash
</td>
<td>
Historical VaR
</td>
<td class="td_nodedate">
01/21/2012
</td>
<td>
1D SD
</td>
<td align="right">
6,771.48
</td>
</tr>
<tr style="background-color: rgb(211, 220, 224);">
<td class="td_pfid">
1726
</td>
<td width="120">
ABC CA Cash
</td>
<td>
Historical VaR
</td>
<td class="td_nodedate">
01/22/2012
</td>
<td>
1D ETL 99
</td>
<td align="right">
22,020.76
</td>
</tr>
<tr>
<td class="td_pfid">
1726
</td>
<td width="120">
ABC CA Cash
</td>
...
JavaScript
$("#pftable tbody tr").click(function (event) { // TABLE ROW CLICK EVENT !!
var prevColor = $(this).css("background-color");
$(this).css("background-color", "Yellow");
// FYI:
// I want to use "thisPfId" to do another lookup in table #pftable to find the FIRST ROW OCCURRENCE of it.
// Then I need to iterate through each occurrence of "thisPfId" and pull all node date values.
// ex/ click on PfId "1726" in the 3rd row, I want to then iterate through each pfId where "td_pfid"="1726"
var rownum = $(this).index();
var thisPfId = $(this).find('.td_pfid').text(); // Portfolio Id, Node Date !!
var thisDate = $(this).find('.td_nodedate').text();
var rows = $("#pftable tr:gt(0)"); // ITERATE THROUGH TABLE ROWS ???
rows.children("td").eq('.td_pfid');
myRowLocated = rows.find('.td_pfid');
var numrows = rows.length;
//rows.find("td:nth-child(1)").find('td_pfid');
/*rows.each(function (index) { // GET NODE DATES FOR THIS PORTFOLIO ID !!
rows.children("td").each(function () {
var td_pfid = $("td:nth-child(1) input").val();
})
});*/
alert("portf id " + thisPfId + "; thisDate " + thisDate + "; rownum " + rownum + "; numrows=" + numrows );
$(this).css("background-color", prevColor);
});