|
Posted by Peter Fox on 02/13/06 03:39
Following on from 's message. . .
>I have several forms that display information from the database after
>users log in. I would like the column titles to be sortable so that
>when the user clicks on a column heading, the data re-displays in
>sorted order of that column. Next time they click on it, it toggles
>the order from ascending to descending, and then back to ascending
>again.
>
>Since I have many forms and each form has different columns, I was
>wondering if there was a method that would be better than a brute force
>approach. What are the best practices for this functionality?
>
>Thanks!
>
ANSWER No 1
You may have noticed that you don't often see this style of UI in web
pages. The main reason is that users need to be educated in how to use
the method and (even with systems they use everyday for years) don't
seem to cotton on very quickly to the tricks often available with column
headings. The secondary reason is the delayed response when requesting
a new database query and web page. "I just clicked on the heading
hoping it would do something useful but I can't see any effect".
So web pages tend to use the more clunky (but (a) perfectly valid and
(b) much more obvious) method of a drop down box(es) saying something
like
Sorted by [Name v] [x] Ascending [go]
ANSWER No 2
You _may_ find search a more productive method than sort+browse.
Depending on the nature of your data and the calibre or your audience
you _may_ want to take them through a menu of
* - select this way
* - select that way
* - select the other way
It is really really really REALLY important to get all users actually
using the system on their own without either giving up or making a hash
or trying to get technical support. After all you (or perhaps the
system designer) should know what people want to use the system for and
farting around with every column under the sun is a waste of everybody's
time. Proper analysis should reduce "I want to look at the data" to
"which jobs are late" or "which of my jobs are late" or "my jobs" or
"job No X".
ANSWER No 3
There are two steps to displaying lists
(1) Selecting from the database
(2) Displaying a table of results
Item 2 is easy to package. 2-dim array to 2-dim table with column-based
function for say converting dates and adding links.
Item 1 can normally be done with one or two switch structures. These
tend to be pretty obvious when looking at the code and pretty specific
to the option chosen.
eg
switch (sortmode) {
case 'name'
$fields = 'name,age,status';
$where = '';
$sort = 'name';
....
}
and these variables get stuffed into a select.
What I personally have done is to create a class which takes a SQL
statement to fetch X records and then (as required) displays them with
all sorts of column variations and headings. The SQL is 'hand crafted'
but the display is half a dozen bog-standard lines.
So, to summarise: You might want to rethink your UI. Displaying is a
mechanical thing that can be stuffed into a class[1] but setting-up SQL
is more easily done in-line with a few switches.
Well, that's /my/ experience.
[1] With the benefit that each time you add functionality to the class
you can re-use it on other projects.
--
PETER FOX Not the same since the poster business went to the wall
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
[Back to original message]
|