Simplest and best column sorting in HTML table?

G

Gregor Kofler

"core library", terrible idea!

Terrible? Can you elaborate on that? Or is it just the name you don't like?
Tables of "200 rows"?

Those things should not be on a HTML page.

Lasrge datacollections should be searched by search strings and prepared
by serverside code and not scrolled foer visual search clientsidde.

*If* I have a table that large sorting makes sense. With 10 rows I don't
need sorting.
So what differense would that make on a talbe of max 20 rows, more is not
accepable anyway.

Swapping whole row elements is just as simple *and* faster.
You are just trying to confuse the issue. See above and ask the OP what
he wants.

Hm, I always thought dorayme is a she... So far the OP hasn't said
anything about the size of her (or his) table.

Gregor
 
D

dorayme

Gregor Kofler said:
... So far the OP hasn't said
anything about the size of her (or his) table.

I have a lot of them of different lengths, not more than one to a
page, the biggest is not more than 200 rows.

I am still looking for a simple sorterer for just towns column
and striper combined. When I have more time I will work this one
out I guess, but if anyone has one that does *just this job*
really reliably, may I grab it please? I have posted a URL of the
sort of table.

http://dorayme.netweaver.com.au/tableSortCandidate.html

Necessary to know in any example is how *not* to have columns
sorted. The first col is towns (alphabetical), second is
postcodes, the rest are not to be sorted.

I can get sort, I can get stripe but buggered if I can find ready
made easy to apply sort and stripe. No urgency. I am quite happy
really to just continue having stripe and with a few tables,
forget the stripe and have sort. It is no big deal. Just see how
bored and magnanimous any of you feel for such an undoubtedly
trivial problem for js experts...
 
E

Evertjan.

dorayme wrote on 31 jan 2010 in comp.lang.javascript:
I have a lot of them of different lengths, not more than one to a
page, the biggest is not more than 200 rows.

I am still looking for a simple sorterer for just towns column
and striper combined. When I have more time I will work this one
out I guess, but if anyone has one that does *just this job*
really reliably, may I grab it please? I have posted a URL of the
sort of table.

http://dorayme.netweaver.com.au/tableSortCandidate.html

Necessary to know in any example is how *not* to have columns
sorted. The first col is towns (alphabetical), second is
postcodes, the rest are not to be sorted.

I can get sort, I can get stripe but buggered if I can find ready
made easy to apply sort and stripe.

The striping was answered nicely by Gregor:

var classNames = ["row0", "row1"], r = yourTable.rows, i;
var l = r.length;
for(i = 0, i < l; i++) {
r.className = classNames[i % classNames.length];
};

In my example, restriping is not neccessary.

===============================

In my example

r.sort();

gives a topdown sort

===

the reversal is:

function sortReversed(a,b){return a>b;};

r.sort(sortReversed);

===

numerical sort:

function sortNumber(a,b){return a - b;};

r.sort(sortNumber);

===

numerical reversed sort I leave to youe imagination.
 
M

Matt Kruse

Tables of "200 rows"?
Those things should not be on a HTML page.

That's a very simplistic view of the web. Tables with thousands of
rows are not uncommon in some situations.

The table-sorting/striping problem is easier to solve, of course, if
you arbitrarily limit the scope so that inefficient solutions perform
just as well as more optimized solutions.

Matt Kruse
 
E

Evertjan.

Matt Kruse wrote on 01 feb 2010 in comp.lang.javascript:
That's a very simplistic view of the web. Tables with thousands of
rows are not uncommon in some situations.

Bad implementations are not uncommon on the web, Matt,
so commonness does not imply solution quality or logic.
The table-sorting/striping problem is easier to solve, of course, if
you arbitrarily limit the scope so that inefficient solutions perform
just as well as more optimized solutions.

I do not agree.

Long tables are nonsensical for readable html.

There is no sense in clienside sorting of such long tables,
even if they are ment for copying and not reading.

They should be sorted serversifde, since the most obvious source of those
tables is a database anyway.
that inefficient solutions perform
just as well as more optimized solutions.

What can be inefficient or optimized about solutions
that "perform just as well"?

Short, easily readable and easily debuggable code
is the only efficiency gain to be won when the performance is just as well.

That gain is not a gain to the client user, only ease and beauty to the
programmer.
 
M

Matt Kruse

Matt Kruse wrote on 01 feb 2010 in comp.lang.javascript:
Bad implementations are not uncommon on the web, Matt,
so commonness does not imply solution quality or logic.

In webappps, for example, long results tables can be very handy to
sort, filter, and manipulate on the client-side. It is much faster
than going back to the server each time, and can be done off-line.
Getting a "dump" of data into a static html document to be handled
later is handy.

Long tables are also good for scanning and getting a feel for how the
results relate to each other. For example, if the rows are colored by
some scheme or if there is a horizontal bar chart in each row, then
scrolling up and down on the table can give the user a quick visual
idea of how the data relates and where logical chunks or groupings of
data exist.
What can be inefficient or optimized about solutions
that "perform just as well"?

There are cases, even without long tables, where the efficiency of a
sort algorithm matter. For example, try creating a more complex table
with multiple tbody tags, a tfoot, colspans and rowspans, more than 25
columns containing complex markup, etc. An inefficient solution may
become unusable with only a couple hundred rows.

During my testing and optimizing of my table sort code, I found that
optimizing for IE6 makes a big difference. Even on shorter tables, you
can cut a second or more off the user's sort time. That is huge in
terms of the user's perception of how quickly the application is
responding.
Short, easily readable and easily debuggable code
is the only efficiency gain to be won when the performance is just as well.

Don't forget flexibility. Your shorter code works in the most
simplistic of cases, but if a developer is faced with a situation
where it breaks, they may not know how to fix it. There are pros and
cons to each way of doing it. Which is why "simplest and best" in the
subject is asking for too much!

Simple, Efficient, Robust. Pick two!

Matt Kruse
 
E

Evertjan.

Matt Kruse wrote on 01 feb 2010 in comp.lang.javascript:
Which is why "simplest and best" in the
subject is asking for too much!

Here we agree.

There is no "best way" without acounting for personal taste.
 
D

Dr J R Stockton

In comp.lang.javascript message <doraymeRidThis-D68949.08194927012010@ne
ws.albasani.net>, Wed, 27 Jan 2010 08:19:49, dorayme <doraymeRidThis@opt
usnet.com.au> posted:
What is best js to provide for client side column sorting with
html tables? Be nice to have the cursor change to a hand on
hovering the table headings. Thank you.

Don't sort the table.

Instead, maintain the data in JavaScript and, on demand, sort it (or a
copy of it) there. Then write the table, with DOM methods.

I have code to sort UK postcodes on my site. Sorting mixed
multinational postal codes should be fun.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top