Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 1st, 2009, 10:50 AM
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>
Reply With Quote
  #2 (permalink)  
Old July 8th, 2009, 11:54 AM
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

is is possible to sort a table with rowspan and colspan in javascript or not?

Could someone please shed some light?

Cheers

C
Reply With Quote
  #3 (permalink)  
Old July 9th, 2009, 04:03 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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
http://joe.fawcett.name/
Reply With Quote
The Following User Says Thank You to joefawcett For This Useful Post:
pallone (July 9th, 2009)
  #4 (permalink)  
Old July 9th, 2009, 05:54 AM
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 Joe,

Thanks for the reply.

As I suspected this will be too difficult. I will have to find another solution.

Cheers

C
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SORTING an table hewstone999 Access VBA 1 June 12th, 2008 09:35 AM
Collapsible table sorting problem sendkamal Javascript 0 February 27th, 2007 12:33 PM
Sorting in Javascript. tannu Javascript How-To 5 July 12th, 2006 05:30 AM
FSO dynamic table sorting nancy Classic ASP Components 0 August 24th, 2005 12:46 PM
XML to HTML Table with Sorting and Distinct VictorMk XSLT 4 April 23rd, 2004 06:29 PM



All times are GMT -4. The time now is 08:04 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.