The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Special Forums > Web Programming, Web 2.0 and Mashups
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-08-2008
garric garric is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 99
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
  #2 (permalink)  
Old 08-09-2008
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
Quote:
Originally Posted by garric View Post
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.
You can't do it with static HTML but you can do it with Perl CGI because the output is dynamic and with Perl (or if you retrieve data from database you can do the sorting at database tier also) you can do the sorting very easily. With a click the page is regenerated with the needed sorting.

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!
  #3 (permalink)  
Old 08-09-2008
garric garric is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 99
Do you have any suggestions? I am not sure I can differentiate between a good one and a bad one?

Regards,
garric
  #4 (permalink)  
Old 08-09-2008
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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? ).
  #5 (permalink)  
Old 04-16-2009
muay_tb muay_tb is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 33
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;
}
Hope this idea helps?

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...
  #6 (permalink)  
Old 04-16-2009
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
Quote:
Originally Posted by muay_tb View Post
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:
Yes it will work. For most applications I will go with this myself also, but sometimes this is not desirable for performance reasons. Especially if the database itself has already been overloaded, having to ask the database again just to change the sorting will be an overkill. In that case you might want to rely on the server-side language (PHP/Perl) or client-side (Javascript-based) to do the sorting instead. Performance may not necessarily be better, but if the database server is on another host then at least it can be freed for serving other database queries.

This is based on observation because in production environment, database server is very often the performance bottleneck.
  #7 (permalink)  
Old 04-16-2009
sneakyimp sneakyimp is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 14
I have had some really satisfactory experiences with YUI tools. In particular, the DataTable. There's a bit of a learning curve, but I think it's worth it.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0