Lee
Way back when i originally posted the problem..
>> Task 1) I wish to implement clickable headers that allow the user to
>> decide upon which column to sort by.
Here we both may have misread/misrepresented the problem - the
solution is the one I wanted, click on the header to reorder the
result set without any Javascript/AJAX at the time.
I look at the underlying data from a query as a result set and that is
what I wanted reordering...
Ady
On 12/01/2009, at 19:19 , Lee Bolding wrote:
>
> This implementation seems to be different from what I thought we were
> talking about.
>
> You're using the click on the header to change the SQL orderby clause,
> what I thought you originally described was a method of reordering the
> resultset of the current page.
>
> Which of these is it that you wanted?
>
> If it's the former, then that's trivial, and you should be able to
> work it out pretty easily. It's the latter that I've been talking
> about. They're complete separate (and unrelated) problems.
>
> On 12 Jan 2009, at 08:34, Adrian Gould wrote:
>
>>
>> Thanks Lee
>>
>> Ok - I have stage one working - the click on a header gives the sort
>> order.
>>
>> I'll be going onto stage two which will be storing the sort state -
>> possibly using a "session" variable to do that... ?
>>
>> Ady
>>
>> //
>> --------------------------------------------------------------------------------------------
>> /* frontend/modules/unit/actions/actions.class.php
>> * snipped down for simplicity
>> */
>>
>> class unitActions extends sfActions
>> {
>> // used to get the sort order for the Unit table
>> protected function getSortOrder($sortBy) {
>> $sortCol = UnitPeer::ID;
>> if ($sortBy=='state') {
>> $sortCol = UnitPeer::STATE_CODE;
>> } elseif ($sortBy=='national') {
>> $sortCol = UnitPeer::NATIONAL_CODE;
>> } elseif ($sortBy=='name') {
>> $sortCol = UnitPeer::NAME;
>> } elseif ($sortBy=='hours') {
>> $sortCol = UnitPeer::NOMINAL_HOURS;
>> }
>> return $sortCol;
>> }
>>
>> // generates the default of all records listed in units table
>> public function executeIndex(sfWebRequest $request)
>> {
>> $sortBy='';
>> if ($request->hasParameter('sortby')) {
>> $sortBy = $request->getParameter('sortby');
>> }
>> $this->sortby = $sortBy;
>> $c = new Criteria();
>> $c->addAscendingOrderByColumn($this->getSortOrder($sortBy));
>> $this->unit_list = UnitPeer::doSelect($c);
>> }
>>
>> // generates a paged set of results from the units table
>> public function executeList(sfWebRequest $request)
>> {
>> $sortBy='';
>> if ($request->hasParameter('sortby')) {
>> $sortBy = $request->getParameter('sortby');
>> }
>> $this->sortby = $sortBy;
>>
>> $c = new Criteria();
>> $c->addAscendingOrderByColumn($this->getSortOrder($sortBy));
>> $pager = new sfPropelPager('Unit', 10);
>> $pager->setCriteria($c);
>> $pager->setPage($this->getRequestParameter('page', 1));
>> $pager->init();
>> $this->unit_list = $pager;
>> }
>>
>> }
>>
>> //
>> --------------------------------------------------------------------------------------------
>>
>> /* frontend/modules/unit/templates/_list.php
>> */
>>
>> <table>
>> <thead>
>> <tr>
>> <th> <?php echo link_to( 'State code', 'unit/index?
>> sortby=state' ) ?></th>
>> <th> <?php echo link_to( 'National code', 'unit/index?
>> sortby=national') ?></th>
>> <th> <?php echo link_to( 'Name', 'unit/index?sortby=name') ?></
>> th>
>> <th> <?php echo link_to( 'Nominal Hours', 'unit/index?
>> sortby=hours') ?></th>
>> </tr>
>> </thead>
>> <tbody>
>> <?php $i=0;
>> foreach ($unit_list 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>
>>
>>
>> //
>> --------------------------------------------------------------------------------------------
>>
>> /* frontend/modules/unit/templates/indexSuccess.php
>> */
>>
>> <h1>Unit List</h1>
>>
>> <?php include_partial('unit/list', array('unit_list' =>
>> $unit_list)) ?>
>>
>> <a href="<?php echo url_for('unit/new') ?>">New</a>
>>
>>
>>
>> //
>> --------------------------------------------------------------------------------------------
>> # frontend/config/routing.yml
>>
>> unit_sort:
>> url: /unit/:sortby/
>> param: { module: unit, action: list }
>>
>> #catch the use of plural units and modules
>> units:
>> url: /units/:sortby/
>> param: { module: unit, action: list }
>>
>> modules:
>> url: /modules/:sortby/
>> param: { module: unit, action: list }
>>
>>
>>>
>
> Lee Bolding
> [email protected]
>
> "a successful framework finds users and sucks and diddles their
> genitalia, it doesnt bend them over and make them squeel like stuck
> pigs." Hani Suleiman, The Bile Blog
>
>
> >
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
-~----------~----~----~----~------~----~------~--~---