2016-07-25 40 views
0

enter image description here工作了数当我使用分页程序排序CakePHP中3它不工作properly.It是显示以下顺序

Sno 
1 
11 
13 
18 
2 
25 
3 
instead of 
Sno 
1 
2 
3 
11 
13 
18 
25 

我的看法页面代码是

  <th> <?= $this->Paginator->sort('Sno') ?></th> 
      <th><?= $this->Paginator->sort('id','Order ID') ?></th> 
      <th><?= $this->Paginator->sort('user_id','Cust ID') ?> </th> 
      <th><?= $this->Paginator->sort('first_name','Cust Name') ?></th> 
      <th><?= $this->Paginator->sort('created_date','Date') ?></th> 
      <th><?= $this->Paginator->sort('order_qty','Order Qty') ?></th> 

任何机构请帮助我。 在此先感谢。

+2

它正在工作,因为它是一个字符串比较。而在'字符串世界'中,'CUS_11 eballes

回答

0

该行为是完全正常的,因为您用于存储ID的列类型是字符串而不是数字。在订购字符串时,11发生在2之前

我建议您更改模式并切换到数字ID。

但是如果因为某些原因,你不能这样做,那么你可以创建一个计算字段存储在控制器你发现电话数值

你必须添加字段

->select(['my_id' => "CAST(REPLACE(id, 'CUS_', '') AS UNSIGNED)"]) 

,并在视图

<?= $this->Paginator->sort('my_id','Order ID') ?> 

记得的字段添加到sortWhitelist

$this->paginate = [ 
     'sortWhitelist' => ['my_id'] 
];