2014-10-09 107 views
0

看着這篇文章 http://www.yiiframework.com/doc/api/1.1/CSort排序的GridView Yii2

它表明您可以排序是一個 'virtial'

在我的GridView的列我有

'columns' => [ 
       [ 
        'label' => 'Name', 
        'attribute' => 'displaynamehtml', 
        'format' => 'raw' 
       ], 

'displaynameashtml' 是屬性組合first_name和last_name並創建可點擊的網址。

要按這個我有:

$dataProvider->setSort([ 
      'attributes' => [ 
       'displaynamehtml' => [ 
        'asc' => 'first_name, last_name', 
        'desc' => 'first_name DESC, last_name DESC', 
        'label' => 'Name' 
       ], 

然而,這並不工作,給我的錯誤 「的foreach爲無效的論點提供()」

任何想法有什麼不好?

回答

0

嘗試像

$dataProvider->setSort([ 
      'attributes' => [ 
       'displaynamehtml' => [ 
        'asc' => [ 
         'first_name' => SORT_ASC, 
         'last_name' => SORT_ASC, 

        ], 
        'desc' => [ 
         'first_name' => SORT_DESC, 
         'last_name' => SORT_DESC, 

        ], 
        'label' => 'Name' 
       ], 
0

我建議有一點不同:

$dataProvider->sort->attributes['displaynamehtml'] = [   
     'asc' => [ 
        'first_name' => SORT_ASC, 
        'last_name' => SORT_ASC, 
       ], 
     'desc' => [ 
        'first_name' => SORT_DESC, 
        'last_name' => SORT_DESC, 
        ], 
    ]; 

模型搜索將這個