I have a poll in my project.In grid I have show the count.
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label' =>"Constituency",
'attribute' => 'constituency',
'value'=>function($data){
return $data["constituency"];
}
],
[
'class' => 'yii\grid\DataColumn',
'label' =>"Count",
'attribute' => 'count',
'value'=>function($data){
return $data->getCount($data["constituency"]);
},
'enableSorting'=>TRUE ,
],
],
My Model
for get count
public static function getCount($constituency){
$cat = Polls::find()->where(['poll_place'=>$constituency])->count();
// $cat = ArrayHelper::map($cat, 'id', 'name');
return $cat;
}
The count column is a custom column.
Can anyone help to sort that column.
I have tried This and this.
Both are failed because my count attribute is not in my DB.
Showing the following error

getCount()?