|
|
 |
| Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 1st, 2009, 11:50 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 234
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
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">
</th>
<th colspan="4">
2007</th>
<th colspan="2">
</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">
</th>
<th colspan="2">
Q1</th>
<th colspan="2">
Q2</th>
<th colspan="2">
</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">
</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">
</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">
</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>
|

July 8th, 2009, 12:54 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 234
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
SORTING A JAGGED TABLE WITH JAVASCRIPT
is is possible to sort a table with rowspan and colspan in javascript or not?
Could someone please shed some light?
Cheers
C
|

July 9th, 2009, 05:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 2,922
Thanks: 0
Thanked 13 Times in 12 Posts
|
|
Well I'd say it's definitely doable, but firstly you'd have to define the requirements. If you sort on a column and one row doesn't have that column, because another column extends into it, what happens? Similarly how do you deal with row spans, are they teated as on row, which row takes precendence in the sort etc?
Once you know that it's just a question of churning out the code which is going to fairly time consuming I'd have thought. I don't think this is a thirty minute job by any means.
__________________
--
Joe
|
|
The Following User Says Thank You to joefawcett For This Useful Post:
|
|

July 9th, 2009, 06:54 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 234
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
SORTING A JAGGED TABLE WITH JAVASCRIPT
Hi Joe,
Thanks for the reply.
As I suspected this will be too difficult. I will have to find another solution.
Cheers
C
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |