View Single Post
  #1 (permalink)  
Old July 1st, 2009, 10:50 AM
pallone pallone is offline
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default SORTING A JAGGED TABLE WITH JAVASCRIPT

Hi,

I use JavaScript to sort tables on the client. However, I now have discovered that if the table is jagged (Rowspan and Colspan) the sorting does not work.

The table get all mixed up and the rowspan and colspan it not respected.

Is it possible to sort a jagged table in JavaScript??????

I'd appreciate any suggestions and help.

Thanks again, all.


This is the function I use to do the comparisson:

function RowCompareNumbers(a, b)
{
var tdArrayA = a.getElementsByTagName('td')
var tdArrayB = b.getElementsByTagName('td')

var aVal, bVal

if(tdArrayA[lastSort].firstChild)
{
aVal = parseInt(tdArrayA[lastSort].firstChild.nodeValue.replace(/\$/g,""))
}
else
{
aVal = 0
}

if(tdArrayB[lastSort].firstChild)
bVal = parseInt(tdArrayB[lastSort].firstChild.nodeValue.replace(/\$/g,""))
else
bVal = 0

return (aVal - bVal);
}

This is the Table:

<table class="example" id="tblGrid" cellspacing="0" border="1">
<thead>
<tr style="top: 0px">
<th style="border-right: 0px; border-top: 0px; left: 0px; border-left: 0px;
border-bottom: 0px; background-color: #859eb5" colspan="2">
&nbsp;</th>
<th colspan="4">
2007</th>
<th colspan="2">
&nbsp;
</th>
</tr>
<tr style="top: 0px">
<th style="border-right: 0px; border-top: 0px; left: 0px; border-left: 0px;
border-bottom: 0px; background-color: #859eb5" colspan="2">
&nbsp;</th>
<th colspan="2">
Q1</th>
<th colspan="2">
Q2</th>
<th colspan="2">
&nbsp;
</th>
</tr>
<tr style="top: 0px">
<th style="border-right: 0px; border-top: 0px; left: 0px; border-left: 0px;
border-bottom: 0px; background-color: #859eb5" colspan="2">
&nbsp;</th>
<th colspan="2">
MAR</th>
<th colspan="2">
APR</th>
<th colspan="2">
Total</th>
</tr>
<tr style="top: 0px">
<th style="border-right: 0px; border-top: 0px; left: 0px; border-left: 0px;
border-bottom: 0px; background-color: #859eb5" colspan="2">
&nbsp;</th>
<th onclick="SortTable(0)">
Total Pages</th>
<th onclick="SortTable(1)">
Cost Gross</th>
<th onclick="SortTable(2)">
Total Pages</th>
<th onclick="SortTable(3)">
Cost Gross</th>
<th onclick="SortTable(4)">
Total Pages</th>
<th onclick="SortTable(5)">
Cost Gross</th>
</tr>
</thead>
<tbody>
<tr>
<th style="left: 0px" rowspan="2">
CARDIOLOGY</th>
<th style="left: 0px">
CARDIOLOGY NEWS</th>
<td>
1.00</td>
<td>
$5,210.00</td>
<td>
1.00</td>
<td>
$5,210.00</td>
<td>
2.00</td>
<td>
$10,420.00</td>
</tr>
<tr>
<th style="left: 0px">
JOURNAL OF THE AMERICAN COLLEGE OF CARDIOLOGY</th>
<td>
2.00</td>
<td>
$12,620.00</td>
<td>
2.00</td>
<td>
$13,154.00</td>
<td>
4.00</td>
<td>
$25,774.00</td>
</tr>
<tr>
<th style="left: 0px">
INTERNAL MEDICINE</th>
<th style="left: 0px">
INTERNAL MEDICINE NEWS</th>
<td>
1.00</td>
<td>
$11,055.00</td>
<td>
1.00</td>
<td>
$11,055.00</td>
<td>
2.00</td>
<td>
$22,110.00</td>
</tr>
<tr>
<th style="left: 0px" rowspan="6">
MULTISPECIALTY</th>
<th style="left: 0px">
AMERICAN FAMILY PHYSICIAN</th>
<td>
1.00</td>
<td>
$11,655.00</td>
<td>
2.00</td>
<td>
$23,310.00</td>
<td>
3.00</td>
<td>
$34,965.00</td>
</tr>
<tr>
<th style="left: 0px">
AMERICAN MEDICAL NEWS - MINI-MASS DEMO</th>
<td>
2.00</td>
<td>
$23,326.00</td>
<td>
1.00</td>
<td>
$11,663.00</td>
<td>
3.00</td>
<td>
$34,989.00</td>
</tr>
<tr>
<th style="left: 0px">
FAMILY PRACTICE NEWS</th>
<td>
1.00</td>
<td>
$12,235.00</td>
<td>
1.00</td>
<td>
$12,235.00</td>
<td>
2.00</td>
<td>
$24,470.00</td>
</tr>
<tr>
<th style="left: 0px">
JAMA MINI</th>
<td>
1.00</td>
<td>
$11,167.00</td>
<td>
1.00</td>
<td>
$11,167.00</td>
<td>
2.00</td>
<td>
$22,334.00</td>
</tr>
<tr>
<th style="left: 0px">
MEDICAL ECONOMICS</th>
<td>
1.00</td>
<td>
$12,140.00</td>
<td>
2.00</td>
<td>
$24,280.00</td>
<td>
3.00</td>
<td>
$36,420.00</td>
</tr>
<tr>
<th style="left: 0px">
NEW ENGLAND JOURNAL OF MEDICINE</th>
<td>
1.00</td>
<td>
$10,090.00</td>
<td>
1.00</td>
<td>
$10,090.00</td>
<td>
2.00</td>
<td>
$20,180.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<th style="left: 0px">
&nbsp;
</th>
<th style="left: 0px">
Total</th>
<td>
11.00</td>
<td>
$109,498.00</td>
<td>
12.00</td>
<td>
$122,164.00</td>
<td>
23.00</td>
<td>
$231,662.00</td>
</tr>
</tfoot>
</table>