简体   繁体   中英

How To Add Sort To Yii2 Gridview for “multi” relational attributes

i have a question in Yii2 Gridview

for example when we have relations like this :

car -> model -> brand -> company -> company_title

the company_title in gridview is not clickable and i can't sort it by asc or desc

how i can do it?

In data provider for each sorting row define sorting rules:

    $dataProvider->sort->attributes['loadDate'] = [
        'asc' => ['status_load.status_time' => SORT_ASC],
        'desc' => ['status_load.status_time' => SORT_DESC],
    ];

    $dataProvider->sort->attributes['supplyingInvoiceNumber'] = [
        'asc' => ['cmd_delivery_osta.supplying_invoice_number' => SORT_ASC],
        'desc' => ['cmd_delivery_osta.supplying_invoice_number' => SORT_DESC],
    ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM