Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp pagination sort descending first

By default when you click on the sort field in pagination it will sort ascending first, is there a way to set it to descending first?

<th><?php echo $this->Paginator->sort('Views', 'views'); ?></th>

I want my users to see most viewed first after clicking on view sort not least viewed.

like image 371
user1032854 Avatar asked Dec 03 '11 00:12

user1032854


1 Answers

To set the default sort direction to be descending, change your code above to this:

<th><?php echo $this->Paginator->sort('Views', 'views, array('direction' => 'desc')); ?></th>

Once activated, the sort direction will toggle between descending and ascending as usual.

like image 73
Trott Avatar answered Nov 17 '22 14:11

Trott