Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19821

Re: Sorting

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Sorting
Date 2013-05-19 04:44 +0200
Organization albasani.net
Message-ID <kn9eb8$hgp$1@news.albasani.net> (permalink)
References <26eac9be-f8cb-4364-b925-51d2fee45d42@e14g2000yqp.googlegroups.com>

Show all headers | View raw


On 2013-05-19 02:40, fulio pen wrote:
> Please open the following page.  My intention is that when clicking
> the head of a column, sorting will  happen.   But nothing has happened
> so far.

I'm not surprised. Clicking one of the links just loads the same page
with a new query string ("?sortByID", "?sortBydob", ...), that's all.
The table won't magically sort itself just because the URL is different.

> http://www.pinyinology.com/css/officials2b.html
> 
> I wrote some js code, but it obviously didn't work.  Please help
> modify the code.  Thanks a lot.

I'm not sure where to start... there aren't any functions that could
modify the table or the source array, and the rest is full of errors.

First of all, you should eliminate the HTML errors.
http://validator.w3.org/ can help with that.

One very obvious problem is this:

<head>
  ...
  <script>
  <!--
     ...
  </script>
</head>
<body>
  ...
  <script>
     ...
  -->
  </script>

Look at where the comments start and end. This may have caused the
syntax error in IE that Andrew posted (can't test due to lack of IE).
Using HTML comments to hide JS code from old browsers hasn't been
necessary for eons; just remove them.

Next, you should let your script read the query string and react
appropriately (by sorting the array before you write() the table).

If you're more interested in the result than how to get there, you could
also use a library to handle the table sorting for you. Many libraries
have something like that built-in or available as a plugin.
For example: http://vxweb.net/sortable#example


- stefan

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Sorting fulio pen <fuliopen@yahoo.com> - 2013-05-18 17:40 -0700
  Re: Sorting Andrew Poulos <ap_prog@hotmail.com> - 2013-05-19 12:06 +1000
  Re: Sorting Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-18 19:10 -0700
  Re: Sorting Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-19 02:15 +0000
  Re: Sorting Stefan Weiss <krewecherl@gmail.com> - 2013-05-19 04:44 +0200
    Re: Sorting fulio pen <fuliopen@yahoo.com> - 2013-05-19 15:43 -0700
    Re: Sorting fulio pen <fuliopen@yahoo.com> - 2013-05-19 16:37 -0700
      Re: Sorting Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-20 00:37 +0000
        Re: Sorting fulio pen <fuliopen@yahoo.com> - 2013-05-20 07:13 -0700
  Re: Sorting Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-19 11:23 +0200

csiph-web