473,785 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Table sorts question

I have been trying to use a couple of javascripts to sort a table by
clicking on column headings.
Sorttable.js and tablesort.js which I found on the web...

I am encountering one problem.
In my table, the content of the first cell in each row contains a link
to another location.

When my table is sorted the displayed table appears correct(sorted)
but when I click on the link in the first column it goes to the link
which was there before the sort took place.

When I view source of the page, it always appears as my original html
page.

Obviously I am a javascript beginner(a stretch at that) so I am having
a hard time understanding what is happening.

It looks to me like the screen display is being changed/sorted, but
the actual html in my html file is not and the click is taking the
values from the source file..

Am I correct?

TIA

Brian
Jul 20 '05 #1
7 2919
BRIAN <bb************ *****@rogers.co m> writes:
I have been trying to use a couple of javascripts to sort a table by
clicking on column headings.
Sorttable.js and tablesort.js which I found on the web...
Could be mine :)
<URL:http://www.infimum.dk/privat/sorttable.html>
It was made as an example for someone in this group, IIRC.
I am encountering one problem.
In my table, the content of the first cell in each row contains a link
to another location.

When my table is sorted the displayed table appears correct(sorted)
but when I click on the link in the first column it goes to the link
which was there before the sort took place.
Highly curious, and sounds mostly like a bug.
Can you show us the page (give a link, or make a small example
file with lines no longer than 72 characters and post it here).
Also specify which browser and version you use.
Obviously I am a javascript beginner(a stretch at that) so I am having
a hard time understanding what is happening.
I'm not, and so do I :)
It looks to me like the screen display is being changed/sorted, but
the actual html in my html file is not and the click is taking the
values from the source file..


The View Source always show the original source, not the current document
structure. I sometimes use this bookmarklet to show the value of innerHTML:

javascript:(doc ument.documentE lement||documen t.body).innerHT ML.replace(/&/g,"&amp;").repl ace(/</g,"&lt;")

It's not pretty, but it shows me what I need. In Mozilla/Netscape 7
you can also use the DOM Inspector to see the current tree structure.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lasse Reichstein Nielsen wrote:
BRIAN <bb************ *****@rogers.co m> writes:

I have been trying to use a couple of javascripts to sort a table by
clicking on column headings.
Sorttable.j s and tablesort.js which I found on the web...

Could be mine :)
<URL:http://www.infimum.dk/privat/sorttable.html>
It was made as an example for someone in this group, IIRC.

I am encountering one problem.
In my table, the content of the first cell in each row contains a link
to another location.

When my table is sorted the displayed table appears correct(sorted)
but when I click on the link in the first column it goes to the link
which was there before the sort took place.

Highly curious, and sounds mostly like a bug.
Can you show us the page (give a link, or make a small example
file with lines no longer than 72 characters and post it here).
Also specify which browser and version you use.

Obviously I am a javascript beginner(a stretch at that) so I am having
a hard time understanding what is happening.

I'm not, and so do I :)

It looks to me like the screen display is being changed/sorted, but
the actual html in my html file is not and the click is taking the
values from the source file..

The View Source always show the original source, not the current document
structure. I sometimes use this bookmarklet to show the value of innerHTML:

javascript:(doc ument.documentE lement||documen t.body).innerHT ML.replace(/&/g,"&amp;").repl ace(/</g,"&lt;")

It's not pretty, but it shows me what I need. In Mozilla/Netscape 7
you can also use the DOM Inspector to see the current tree structure.

/L


Like the original poster, I am a javascript beginner. I, too, have been
working with Stuart Langridge's sorttable.js:

http://www.kryogenix.org/code/browser/sorttable/

I like it because it's very simple to implement. Unfortunately, I'm
having two problems with it.

1. He created a class called "sortbottom " for rows which contain data
such as totals so that they'll always be placed in the bottom row. But
he didn't create a class called "sorttop" or "static" for those rows
that aren't the top row but should remain in place rather than getting
sorted. It's easier to show than explain:

http://www.elementarydesign.com/Baup...ryCompact.html

BTW, I got much of the (x)html/css from Elderweb.com's excellent "When
You Absolutely, Positively Need a Table." It's valid code and very
useful... but it would be more useful if I could get the sorttable.js to
support the markup.

2. Javascript seems to choke when it comes to sorting numbers with
recursive commas. I've seen some work in this area by a frequent poster

http://www.merlyn.demon.co.uk/js-maths.htm#RComma

but I lack the ability to take his work and make it work in sorttable.js

I've been working for a week or so on a number of ideas, none of them
even close to successfully. Any help would be greatly appreciated.

Thanks,

abc3

Jul 20 '05 #3
JRS: In article <YF************ ***@nwrdny02.gn ilink.net>, seen in
news:comp.lang. javascript, aboycalled3 <ab*********@my NOrealSPAMbox.c om>
posted at Fri, 12 Dec 2003 20:37:12 :-

2. Javascript seems to choke when it comes to sorting numbers with
recursive commas. I've seen some work in this area by a frequent poster

http://www.merlyn.demon.co.uk/js-maths.htm#RComma

but I lack the ability to take his work and make it work in sorttable.js

You need to be aware of the importance of the difference in javascript
between a Number and a String.

A Number is a 64-bit IEEE floating-point double, and can be used
arithmetically.

A String is an ordered arrangement of characters, and can be input or
output.

There is automatic conversion between Number and String, which quite
often does what is wanted.

If something contains commas, it cannot be a Number and AFAICS it must
be a String.

Using the default sorting functions :

Number sorts use the numerical value of the Number, sorting into
numerical order.

String sorts use lexical alphanumerical order, starting from the left.

Thus 3 < 2e4, but "3" > "2e4".

To get numerical-magnitude-order by default-sorting Strings, the strings
must be such that the numbers are correspondingly-formatted and the
"ones" are all in the same place; as it happens, it does not matter
whether the shorter numbers are padded with space or zero, provided that
all use the same. They must also not be signed numbers (generally).

You can define any comparison function you like for sorting; you could
even sort a list of numbers into alphabetical order after translation
into Danish, if you could count in Danish words.

Really, commas should only be used when numbers are presented for human
reading; they add no information.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.
Jul 20 '05 #4
Dr John Stockton wrote:
JRS: In article <YF************ ***@nwrdny02.gn ilink.net>, seen in
news:comp.lang. javascript, aboycalled3 <ab*********@my NOrealSPAMbox.c om>
posted at Fri, 12 Dec 2003 20:37:12 :-
2. Javascript seems to choke when it comes to sorting numbers with
recursive commas. I've seen some work in this area by a frequent poster

http://www.merlyn.demon.co.uk/js-maths.htm#RComma

but I lack the ability to take his work and make it work in sorttable.js


You need to be aware of the importance of the difference in javascript
between a Number and a String.

A Number is a 64-bit IEEE floating-point double, and can be used
arithmetically.

A String is an ordered arrangement of characters, and can be input or
output.

There is automatic conversion between Number and String, which quite
often does what is wanted.

If something contains commas, it cannot be a Number and AFAICS it must
be a String.

Using the default sorting functions :

Number sorts use the numerical value of the Number, sorting into
numerical order.

String sorts use lexical alphanumerical order, starting from the left.

Thus 3 < 2e4, but "3" > "2e4".

To get numerical-magnitude-order by default-sorting Strings, the strings
must be such that the numbers are correspondingly-formatted and the
"ones" are all in the same place; as it happens, it does not matter
whether the shorter numbers are padded with space or zero, provided that
all use the same. They must also not be signed numbers (generally).

You can define any comparison function you like for sorting; you could
even sort a list of numbers into alphabetical order after translation
into Danish, if you could count in Danish words.

Really, commas should only be used when numbers are presented for human
reading; they add no information.


Thank you, Dr Stockton, both for the website and for following up with
the above post. I have a much better sense of the philosophy than I
would without your assistance. But I'm still not sure how to apply your
suggestions.

1. Should I represent numbers like 10,234,567,890 as 10234567890? It
would be trivial in the spreadsheet I use to prepare the data. But while
I realize the commas don't add in any information, the end-product is
intended for human reading and I have a hard time reading the numbers
withouth them. I'm not sure I'd be comfortable with that solution.

2. Should I idenify numbers which use recursive commas, strip the
commas, sort them, and then reinsert the commas?

Sorttable.js works out types for data:

<code snippet>

// Work out a type for the column
if (table.rows.len gth <= 1) return;
var itm = ts_getInnerText (table.rows[1].cells[column]);
sortfn = ts_sort_caseins ensitive;
if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
if (itm.match(/^[£$]/)) sortfn = ts_sort_currenc y;
if (itm.match(/^\s*-?[\d\.]+\%?\s*$/)) sortfn = ts_sort_numeric ;

</code snippet>

Would it make sense to add in a type for numbers with recursive commas,
e.g.,

if (itm.match(/^(.*\s)?([-+\u00A3\u20AC]?\d+)(\d{3}\b)/)) sortfn =
ts_sort_recursi ve_comma;

(pattern matching stolen directly from function RComma(S) at
http://www.merlyn.demon.co.uk/js-maths.htm#RComma)

and then strip the commas, sort the data, and add the commas back in
(which I can suggest but don't know how to accomplish -- has anyone
already written this function)?

3. Or is there a better way?
Jul 20 '05 #5
Re String/Number comparisons.

Why not create the table in Javascript from a 2D Array of Objects?

Use the DOM to create a table, and then sort using the Array rather than
Strings from the table cells.

I have a working version at work. It sorts correctly on Numbers,
Strings, and Dates.

Sort the Array, then reload the table.

Jul 20 '05 #6
Dr John Stockton <sp**@merlyn.de mon.co.uk> writes:
You can define any comparison function you like for sorting; you could
even sort a list of numbers into alphabetical order after translation
into Danish, if you could count in Danish words.


For no apparent reason, I have made a converter from numbers to Danish:
<URL:http://www.infimum.dk/privat/toDanishNumbers .html>
(No work has been put into making it work in less than standard compliant
browsers, and it uses both "eval" and "toFixed" :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
JRS: In article <_i************ *****@nwrdny02. gnilink.net>, seen in
news:comp.lang. javascript, aboycalled3 <ab*********@my NOrealSPAMbox.c om>
posted at Sat, 13 Dec 2003 17:49:46 :-
recursive commas.

BTW, 'recursive' applies only to the method of generation. The
resulting string is just as any other method would give.

Please do not quote more than is necessary.

1. Should I represent numbers like 10,234,567,890 as 10234567890? It
would be trivial in the spreadsheet I use to prepare the data. But while
I realize the commas don't add in any information, the end-product is
intended for human reading and I have a hard time reading the numbers
withouth them. I'm not sure I'd be comfortable with that solution.
The beginning of this thread is not at present available to me; I do not
see how the spreadsheet relates to the javascript. But AIUI
spreadsheets also store numbers as standard binaries, and strings as
rows of characters. If your sheet shows commas, that is a display
option.

You could have numbers shown with commas in one column, for reading, and
the same numbers without commas, for exporting.

2. Should I idenify numbers which use recursive commas, strip the
commas, sort them, and then reinsert the commas?
No. If they have commas, they are not numbers.

Would it make sense to add in a type for numbers with recursive commas,
You could do, but ISTM that you should know what you are sorting. A
date dd/mm/yyyy should probably not be sorted in the same way as a part
number kk/qq/aaaa.

3. Or is there a better way?


Preferably, sort on the binary numbers themselves.
Otherwise, sort on any string form, provided that it had been padded so
that the twos of 2, 12, 112, 1112, etc. are all at the same distance
from the left. Other constant characters make no difference; the
essential is that an alphanumeric short should give also numeric order.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
7655
by: Ian Rastall | last post by:
I'm doing a small project right now where I create a table from a database. This is the code, which Dreamweaver, for the most part, has written: *** <?php mysql_select_db($database_tdream, $tdream); $query_rstdream = "SELECT * FROM albums ORDER BY `year` ASC"; $rstdream = mysql_query($query_rstdream, $tdream) or die
3
13592
by: Raghuram Banda | last post by:
Hi, I was strucked in a problem, basically I'm working on Sortable Table and the table is created using HTML Tags and one of the fields in the table contain Date in unix format (something like Tue Sep 02 01:00:00 2003). I wrote the script using DOM. I collected innerHTML of a particular cell and checked whether it a string or not (using isNaN) and based on that I sorted the rows based on a column. Coming to this date field my sort...
6
7732
by: Finn Newick | last post by:
By defining a style as follows: @media aural, handheld {td.layout {display:block;}} I'm hoping to linearise layout tables when viewed by screenreaders and handheld devices (it is also be in some selectable user preferences). This works as intended in Netscape 7 - all the cells stack vertically above each other nicely, but not in Internet Explorer 6 where the only display property that td will respond to seems to be 'none'.
1
1766
by: Jethro | last post by:
This may be an easy question for you experienced guys, but not for me. I have written lots of code in C, but not C++ and not in windows (old fart). I'm working on a simple program to learn the language and how it's used. What I've learned so far, is that VC++ will do all sorts of stuff "automagically" that used to take time to build from scratch.
11
3581
by: Norman L. DeForest | last post by:
Am I misunderstanding the CSS specifications or is Firefox (version 1.0.6) (and Opera) doing the wrong thing? It appears that Firefox 1.0.6 includes the border in width calculations for tables but not in height calculations. Oh, and Opera version 8.02 does the same thing. |<-->| |<-->| <------ border |<------------>| <------ table contents
2
11360
by: G.W. Lucas | last post by:
I apologize if this is a RTFM question, but I have not been able to find a definitive answer elsewhere. Does a "REINDEX TABLE" lock the table while it is working? Can applications write data to the table during the REINDEX? I am working on a real-time application that handles over 2 million "events" per day and runs 7-by-24. Most of these events involve an UPDATE to one or two tables, though a small subset involve a bit more work. ...
6
1423
by: Rosy | last post by:
I am setting up a DB for our company and am at a loss on the best way to handle some of the records. I have a table (tblJobs) that houses the basic info on the job (when, where, what, who). These jobs are assigned a job number based on the year and autonumber (05-3589). However, sometimes these jobs spawn new jobs that have to keep the original job number and add an alphabet (05-3589A). I have another table (tblTime) that houses the...
2
2715
by: Brian Mitchell | last post by:
Ok, I know this is an elementary question but I have a data grid that is bound to a data table and I can't seem to find a way to match the selected row in the grid with it's respective row in the underlying data table. If the rows in the grid are in the same order as the rows in the table then I can use the Datagrid.CurrentRowIndex to return the same row from the data table. But if the user sorts the data in the grid then the row order...
13
2782
by: Pablo | last post by:
Hi at all I'ld like to center a table crossbrowser therefore I wrote: <sryle> table {width:80%;margin-left:auto;margin-right:auto;} </style> firefox work fine but MSIE set the margin to zero Thank in advance
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.