簡體   English   中英

$ this-> Paginator-> sort不適用於cakephp 3中的數字

[英]$this->Paginator->sort is not working for number in cakephp 3

在此處輸入圖片說明 當我在cakephp 3中使用分頁器排序時,它無法正常工作。它顯示以下順序

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>

有沒有人可以幫助我。 提前致謝。

這種行為是完全正常的,因為用於存儲ID的列類型是字符串,而不是數字。 訂購字符串時,碰巧112之前

我建議您更改架構並切換為數字ID。

但是,如果由於某些原因而無法執行此操作,則可以創建一個計算字段來存儲數值

在控制器中的查找調用中,您必須添加字段

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

並認為

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

記得將字段添加到sortWhitelist

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM