There's a JQuery table sorter on the JQuery site that will do your  
first 2 requirements.

Not sure about the 3rd requirement, you may have to modify it yourself  
to achieve that.

On 9 Jan 2009, at 09:25, Adrian Gould wrote:

>
> Hi everyone
>
> I have been trying to work out how to create a sortable table without
> AJAX [looking at progressive enhancement] as a first stage of a small
> application I am writing as practice for teaching next semester.
>
> Scenario:
> The UNIT entity: unit(id, name, state_code, national_code) contains
> data about units of study that are available to students.
> I have successfully used the sfPropelPager to create a paginated table
> of the results in an unsorted manner.
>
> Problems:
>
> Task 1) I wish to implement clickable headers that allow the user to
> decide upon which column to sort by.
> Task 2) Clicking a header twice reverses the sort
> Task 3) Clicking a header three times cancels the sorting direction
> and thus returns the data to the entered data order [unsorted]
>
>
> Anyone give me the hints to help implement this?
>
> Thanks
>
> Ady
> -------------------------------
>
> In the /apps/frontend/modules/unit/actions/actions.class.php I have
> [reduced for simplicity]:
>
> class unitActions extends sfActions
> {
>
>   public function executeIndex(sfWebRequest $request)
>   {
>     $this->unit_list = UnitPeer::doSelect(new Criteria());
>   }
>
>   public function executeList(sfWebRequest $request)
>   {
>       $c = new Criteria();
>     $c->addAscendingOrderByColumn(UnitPeer::NAME);
>     $pager = new sfPropelPager('Unit', 10);
>     $pager->setCriteria($c);
>     $pager->setPage($this->getRequestParameter('page', 1));
>     $pager->init();
>     $this->unit_list = $pager;
>   }
>
> }
>
> -----------
> In the /apps/frontend/modules/unit/templates/listSuccess.php file:
>
>
> <?php echo $unit_list->getNbResults() ?> results found.<br />
> Displaying results <?php echo $unit_list->getFirstIndice() ?> to  <?
> php echo $unit_list->getLastIndice() ?>.
>
> <table cellspacing="0">
>   <thead>
>     <tr>
>       <th class="state">State code</th>
>       <th class="national">National code</th>
>       <th class="name">Name</th>
>       <th class="nominal">Nominal hours</th>
>     </tr>
>   </thead>
>   <tbody>
>     <?php $i=0;
>               foreach ($unit_list->getResults() as $unit): ?>
>     <tr class="<?php echo ($i=($i==0?1:0)) ? 'even' : 'odd' ?>">
>     <td><?php echo $unit->getStateCode() ?></td>
>       <td><?php echo $unit->getNationalCode() ?></td>
>       <td><a href="<?php echo url_for('unit/show?id='.$unit-
>> getId()) ?>"><?php echo $unit->getName() ?></td>
>       <td><?php echo $unit->getNominalHours() ?></td>
>     </tr>
>     <?php endforeach; ?>
>   </tbody>
> </table>
>
>
> <?php if ($unit_list->haveToPaginate()): ?>
>   <?php echo link_to('&laquo;', 'unit/list?page='.$unit_list-
>> getFirstPage()) ?>
>   <?php echo link_to('&lt;', 'unit/list?page='.$unit_list-
>> getPreviousPage()) ?>
>   <?php $links = $unit_list->getLinks(10); foreach ($links as
> $page): ?>
>     <?php echo ($page == $unit_list->getPage()) ? $page :
> link_to($page, 'unit/list?page='.$page) ?>
>     <?php if ($page != $unit_list->getCurrentMaxLink()): ?> - <?php
> endif ?>
>   <?php endforeach ?>
>   <?php echo link_to('&gt;', 'unit/list?page='.$unit_list-
>> getNextPage()) ?>
>   <?php echo link_to('&raquo;', 'unit/list?page='.$unit_list-
>> getLastPage()) ?>
> <?php endif ?>
>
>
>
>
>
>
>
> Adrian Gould
> [email protected]
>
>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to