Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-08-2008, 12:46 PM
JGD JGD is offline
Junior Member
 
Join Date: Jul 2008
Posts: 9
Default Sorting table columns

Hi,

I'm trying to create a facility which allows the user to sort a returned set of values based on column headings. Any ideas?

Any feedback is appreciated,

Regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-09-2008, 02:32 AM
Member
 
Join Date: Jul 2008
Posts: 37
Default

Assuming your dataset is paginated, the simplest was is to make the column headings links that add a parameter to that determines the sort order when you pull the result from the database.
eg.
Code:
<a href="?column=name&order=asc">Name</a><a href="?column=email&order=asc">Email</a>
This can easily be extended by doing things such as:
  • making the links dynamic, allowing asc or desc ordering.
  • adding html/css to highlight the sorted row (eg. an arrow)
  • storing the order in a session/cookie so it is persisted if the user returns to the page
  • performing the lookup via JavaScript (Ajax) to avoid a page load.
Depends what you want to achieve.
__________________
Brenton Alker
Brisbane, Australia

http://blog.tekerson.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-11-2008, 11:06 AM
Junior Member
 
Join Date: Jul 2008
Posts: 6
Default

Hello ,

see this link : sorttable: Make all your tables sortable
I user sortable with Javascript and it so fast .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-11-2008, 12:31 PM
Junior Member
 
Join Date: Oct 2007
Location: Augusta, GA
Posts: 9
Default

Hello,

In addition to providing initial sorting functionality, anticipate the the user will want to vary their sorting once they have it on the page just by clicking the column header. While functionality such as passing parameters to the controller to return the data from the database in a particular sort order, it does increase the amount of server-side code and logic to handle the sorting. Also, when and if you change the number of columns, you'll have to cascade the change across your sorting logic. Not to mention the page refresh each time.

In most cases, implementing a client-side sortable grid (table) would be the best solution. Work with the customer to determine their preferred default sort, and let them change the sort of the data at the client-side (no need for page refresh or AJAX call - assuming the data stays the same based on sort).

I highly suggest you check out dojo, as ZF is currently integrating Dojo. Do a little reading on building a grid (some great ones available as dojoX components), you'll probably be suprised how easy it is.

Even if you have a paginated data source, implementing an AJAX call back to the server is quite easy using Dojo. Get use to it now...it will be here soon =)

Hope this helps,

Steve
__________________
Steve Siebert
Zend Certified Engineer
General Dynamics IT
www.get-dev.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB 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. The time now is 09:55 PM.