It's nice.
I hack the cakephp core because i think this is a functionability that
cakephp must to have in the core.
In my app I expend paginator class like othe classes to improve the
functionability
On 28 feb, 17:46, Nasko <[EMAIL PROTECTED]> wrote:
> Why did you have to hack in the core. The third parameter of
> PaginatorHelper::sort() - array options is just for that. You could
> pass 'class' => 'whatever' in it
>
> I'm using this in the view:
>
> $sortDir = $paginator->sortDir();
> $sortKey = $paginator->sortKey();
> switch($sortKey) {
> case 'id':
> $id_options['class'] = $sortDir;
> break;
> case 'type':
> $type_options['class'] = $sortDir;
> break;
> case 'subject':
> $subject_options['class'] = $sortDir;
> break;
> case 'valid':
> $valid_options['class'] = $sortDir;
> break;
> case 'created':
> $created_options['class'] = $sortDir;
> break;
>
> }
>
> and then:
> <tr>
> <th class="td-id"><?php echo $paginator->sort('ID', 'id',
> $id_options);?></th>
> <th><?php echo $paginator->sort('Type', 'type', $type_options);?></
> th>
> <th><?php echo $paginator->sort('Subject', 'subject',
> $subject_options);?></th>
> <th><?php echo $paginator->sort('Valid', 'valid', $valid_options);?></th>
>
> <th><?php echo $paginator->sort('Created', 'created',
> $created_options);?></th>
> <th class="td-actions">Actions</th>
> </tr>
>
> this way class is either 'asc', 'desc' or is not set in the options
> array
>
> On Feb 28, 5:39 pm, "David B." <[EMAIL PROTECTED]> wrote:
>
> > Sorry, in the last function I forget to delete an echo and an
> > initialized var, this is the right function
>
> > function sort($title, $key = null, $options = array()) {
> > $options = array_merge(array('url' => array(), 'model' =>
> > null),
> > $options);
> > $url = $options['url'];
> > unset($options['url']);
>
> > if (empty($key)) {
> > $key = $title;
> > $title =
> > __(Inflector::humanize(preg_replace('/_id$/', '',
> > $title)), true);
> > }
>
> > $dir = 'asc';
> > $field = '';
> > if (eregi('[[:alpha:]]\.[[:alpha:]]',$key)) {
> > list($model,$field) = explode('.',$key);
> > }
> > if ($this->sortKey($options['model']) == $key &&
> > $this->sortDir($options['model']) == 'asc') {
>
> > $dir = 'desc';
> > }
>
> > if ($this->sortKey($options['model']) == $key ||
> > $this->sortKey($options['model']) == $field){
>
> > $options = array_merge(array('class' => 'sorted ' .
> > $dir),
> > $options);
> > }
>
> > $url = array_merge(array('sort' => $key, 'direction' =>
> > $dir), $url,
> > array('order' => null));
> > return $this->link($title, $url, $options);
> > }
>
> > On 28 feb, 16:33, "David B." <[EMAIL PROTECTED]> wrote:
>
> > > Well it isn't my need. I think i don't explain the question well
>
> > > I want to set a CSS class to the sorted field, I modified the helper
> > > paginator to do this, this is the code:
>
> > > IN /cake/libs/view/helpers/paginator.php change function sort for
> > > this:
> > > function sort($title, $key = null, $options = array()) {
> > > echo $id;
> > > $options = array_merge(array('url' => array(), 'model' =>
> > > null),
> > > $options);
> > > $url = $options['url'];
> > > unset($options['url']);
>
> > > if (empty($key)) {
> > > $key = $title;
> > > $title =
> > > __(Inflector::humanize(preg_replace('/_id$/', '',
> > > $title)), true);
> > > }
>
> > > $dir = 'asc';
> > > if (eregi('[[:alpha:]]\.[[:alpha:]]',$key)) {
> > > list($model,$field) = explode('.',$key);
> > > }
> > > if ($this->sortKey($options['model']) == $key &&
> > > $this->sortDir($options['model']) == 'asc') {
>
> > > $dir = 'desc';
> > > }
>
> > > if ($this->sortKey($options['model']) == $key ||
> > > $this->sortKey($options['model']) == $field){
>
> > > $options = array_merge(array('class' => 'sorted '
> > > . $dir),
> > > $options);
> > > }
>
> > > $url = array_merge(array('sort' => $key, 'direction' =>
> > > $dir), $url,
> > > array('order' => null));
> > > return $this->link($title, $url, $options);
> > > }
>
> > > In your CSS stylesheet add this classes
>
> > > th a.sorted{
> > > background-color: #DDD !important;}
>
> > > th a.desc{
> > > background: transparent url('/img/icon/bullet_arrow_up.png') no-
> > > repeat right center;}
>
> > > th a.asc{
> > > background: transparent url('/img/icon/bullet_arrow_down.png') no-
> > > repeat right center;
>
> > > }
>
> > > This is the HTML result:
>
> > > <th>
> > > <th><a
> > > href="/access/index/17/page:1/sort:date/direction:asc">Time</
> > > a></th>
> > > <th><a href="/access/index/17/page:1/sort:id_customer/
> > > direction:asc">Client</a></th>
> > > <th><a class="sorted asc" href="/access/index/17/page:1/
> > > sort:Condition.id_vip/direction:asc">Vip</a></th>
> > > <th><a href="/access/index/17/page:1/sort:id_condition/
> > > direction:asc">Condition</a></th>
> > > <th><a href="/access/index/17/page:1/sort:accepted/
> > > direction:asc">Accepted</a></th>
> > > </tr>
>
> > > I use a regular expression to validate when the sort key is in this
> > > format Model.field
>
> > > CakePHP is nice!
>
> > > On 22 feb, 19:15, "b logica" <[EMAIL PROTECTED]> wrote:
>
> > > > Put those headers in the thead and tfoot of your table:
>
> > > > <table id="whatever">
> > > > <thead>
> > > > <th><?= $paginator->sort('id') ?></th>
> > > > ...
> > > > </thead>
> > > > <tfoot>
> > > > <th><?= $paginator->sort('id') ?></th>
> > > > ...
> > > > </tfoot>
> > > > <tbody>
> > > > ...
> > > > </tbody>
> > > > </table>
>
> > > > CSS:
> > > > #whatever thead a, #whatever tfoot a {}
>
> > > > On Fri, Feb 22, 2008 at 10:58 AM, David B. <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi! We are developing and application with cakephp 1.2.0.6311 and we
> > > > > miss one feature or we don't find.
>
> > > > > When you show the paginator under the view, <th><?php echo
> > > > > $paginator-
> > > > > >sort('id');?></th>, How could we pass a class to this TH or the
> > > > > inside A element to apply some CSS style to the selected sort index?
>
> > > > > We want to apply a nice arrow for ASC $ DESC sort and some color to
> > > > > the background to emphasize the sort criteria
>
> > > > > Best regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---