![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Web Programming, Web 2.0 and Mashups Discuss Web Programming and Web Server Administration, including LAMP, Apache, MySQL, Flash, HTML, SEO, Mashups and other Web APIs and topics. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tables and borders | amatuer_lee_3 | Shell Programming and Scripting | 9 | 03-10-2009 10:18 PM |
| tables in scripts | Celine19 | Shell Programming and Scripting | 7 | 07-08-2008 11:49 AM |
| Converting tables of row data into columns of tables | justthisguy | Shell Programming and Scripting | 7 | 07-16-2007 05:42 PM |
| Routing tables | kingdbag | UNIX for Dummies Questions & Answers | 9 | 10-06-2006 09:01 PM |
| viewing tables | itldp | UNIX for Dummies Questions & Answers | 2 | 12-17-2003 09:19 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Sortable Tables in Javascript
Hi,
I am writing a web application using Perl-CgI mostly. I wanted to integrate a table in which I was capable of sorting columns and I don't think this is possible with static HTML code. Can someone help me integrating some javascript code into what I have to acheive the above? Regards, garric |
|
||||
|
Quote:
This forum is an example. You can click on header to sort by a given field with a page refresh each time. There are indeed some open-source Javascript (or AJAX) tabular sort mechanisms out there. If you search, you ought to find some out there. The obvious advantage is eliminating a page refresh so the apparent performance is better. The downside is your application will become more browser-dependent as you rely more on Javascript. And, debugging javascript written by others is a nightmare - make sure you get a good one! |
|
||||
|
I don't, because in the past, I wrote myself for customized sorting needs. But I do have experience working with some third-party Javascript that requires a lot of debugging to find out why something does not work as expected. Especially some of today's Javascript libraries or components are delivered packed and obfuscated, that makes it next to impossible to trace.
Today I just tried a third-party Javascript sort component at work out of coincidence, but I'm not naming it here because it is written for Java EE-based deployments and won't work in non-Java EE environment, so it's useless for you. Doesn't server-side sort work for you? As I said, it is a lot more reliable and will work on any Web browser (even with Javascript off). Sure you can venture with client-side sort (or hybrid) but you must have the preparation that things may perhaps not come so smoothly (as always, your mileage may vary, so chances are you may get it working quite smoothly? ). |
|
||||
|
might sound obvious as i know its possible in PHP but...
why not grab records from the database using a set query whereby you pass a sort (or order by) parameter to the function and in the perl manipulate the rows fetched and re-display: Example (forgive me if my perl is awol but you will get the idea): whereby the $sortValue is the ORDER BY column name. @mydata=&grabDataFromDB($sortValue); all that grabDataFromDB does is this: Code:
sub grabDataFromDB($sortBy)
{
if ($sortBy != "")
{
$query="select * from table ORDER BY $sortBy";
}
else
{
$query="select * from table";
}
# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);
# SELECT DB
$connect->selectdb($database);
# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($query);
# HTML TABLE
$output = "<table border='1'><tr>";
$output .= "<th>id</th>";
$output .="<th>product</th>";
$output .= "</tr>";
# FETCHROW ARRAY
while (@results = $execute->fetchrow()) {
$output .= "<tr><td>"
.$results[0]."</td><td>"
.$results[1]."</td><td>"
$output .= "</tr>";
}
$output .= "</table>";
$output;
}
In your html you could set each header as hyperlink to the same page but also pass the name of the column to sort by... |
|
||||
|
Quote:
This is based on observation because in production environment, database server is very often the performance bottleneck. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|