I am trying to use the sort element of the dataprovider at a gridview but it does not work,what maybe wrong?
I use the bellow vode at controller
$dataProvider = new \yii\data\SqlDataProvider([
'sql' => 'select id,email,name,username,role from mechanics ;',
'totalCount' => $count,
'key' => 'id',
'sort' => [
//'defaultOrder' => ['name' => SORT_DESC,],
'attributes' => ['email','name','username','role']
],
'pagination' => [
'pageSize' => 50,
]
]);
at view
<?=
yii\grid\GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'email',
'username',
'name',
['attribute' => 'role',
'value' => function($model) {
$usertype=new \app\models\Mechanics();
$type=$usertype->Usertype();
return $type[$model['role']];
}
],
[
'class' => 'yii\grid\ActionColumn',
// you may configure additional properties here
'buttons' => [.....