2016-07-25 39 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'] 
];