按降序排序表头,无需排序整个数据库表 [英] Sort table header in descending order page wise without sorting whole database table

查看:137
本文介绍了按降序排序表头,无需排序整个数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何只在该页面中排序表头,而不排序整个table.is这可能在cakephp?请给我看一些示例代码。我的意见是

 <?php 
echo $ url = $ this-> Paginator-> sort 'ID','id',array('direction'=>'desc'));
$ arrow = getArrow($ url);
?>

这是我的控制器:

$ this-> paginate = Set :: merge($ this-> paginate,array('OrderFinalized'=> array


'limit'=> 4,
'conditions'=> $ condition_ary,
'joins'=& (
'table'=>'order_entry_headers',
'alias'=>'OrderEntryHeaders2',
'type'=>'inner',
'foreignKey' => false,
'conditions'=> array('OrderEntryHeaders2.id = OrderFinalized.order_entry_headers_id'),

'order'=> array(
'OrderEntryHeaders2 .id'=>'desc'

),

是查询:

  $ result = $ this-> OrderEntryHeader-> query(SELECT(value + 1)as val FROM order_entries_seq ORDER BY OrderEntryHeader.id desc); 

当我排序第一页的顺序,我得到最后的结果从数据库table.i想



exid_id名称(第1页)ASC

1 A
2 B
3 C
4 D



DESC ID名称
4 D
3 C
2 B
1 A

解决方案

你想要的是从数据库中检索数据,然后使用排序。最简单的方法是使用JavaScript。



您需要前端/客户端表格排序器,如



http://tablesorter.com/docs/#Demo


$ b


这是可能在CakePHP ,请在数组排序中a href =http://book.cakephp.org/2.0/en/models/callback-methods.html#afterfind =nofollow> afterFind方法


I would like to know how to sort a table header only in that page without sorting the whole table.is this possible in cakephp? please show me some sample code. my view is

    <?php
                    echo   $url = $this->Paginator->sort('ID', 'id',array('direction' => 'desc'));
                    $arrow = getArrow($url);
                  ?>

This is my Controller:

$this->paginate = Set::merge($this->paginate, array('OrderFinalized' => array(


                        'limit'=>4,
                        'conditions' => $condition_ary,
                                'joins' => array(
                                    array(
                                        'table' => 'order_entry_headers',
                                        'alias' => 'OrderEntryHeaders2',
                                        'type' => 'inner',
                                        'foreignKey' => false,
                                        'conditions' => array('OrderEntryHeaders2.id = OrderFinalized.order_entry_headers_id'),

                                            'order' => array(
'OrderEntryHeaders2.id'=> 'desc'
 )
                ),

this is the query:

$result = $this->OrderEntryHeader->query("SELECT (value+1) as val FROM order_entries_seq ORDER BY OrderEntryHeader.id desc ");

When I sort the first page desending order I get the last results from the database table.i want to sort only the results from that page.it should not change while navigation.

ex- id name (page 1) ASC
1 A 2 B 3 C 4 D

DESC id name 4 D 3 C 2 B 1 A

解决方案

What you want is to retrieve data from a database and then use the sorting. The easiest way is by using JavaScript.

You need front-end / client-side table sorter like

http://tablesorter.com/docs/#Demo

is it still possible to do with sort function?

It is possible in CakePHP, make array sort in afterFind method

这篇关于按降序排序表头,无需排序整个数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆