如何使列可排序(Gridview小部件)

时间:2015-12-10 13:31:45

标签: gridview yii2

也许我需要对搜索模型进行更改? 查看索引文件:



<?= 
  GridView::widget([
  'dataProvider' => $dataProvider,
  'filterModel' => $searchModel,
  'columns' => 
   [
    //'address'
    [
      'label' => 'address',
      'value' => function($model)
      {
        return
          $model->payment_method.' '.
          $model->payment_address_1.' '.
          $model->payment_address_2.' '.
          $model->payment_city.' '.
          $model->payment_postcode.' '.
          $model->payment_country.' '.
        $model->payment_zone.' ';
      },
    ],
  ]
?>
&#13;
&#13;
&#13;  ///////////////////////////////////////////

1 个答案:

答案 0 :(得分:0)

您只需在搜索模型中添加:

public function search($params)
{
  ......

  $dataProvider = new ActiveDataProvider([
        'query' => $query,
        'sort'=> ['defaultOrder' => ['your_column_name'=>SORT_DESC]],
  ]);

  ......
}