I need to display number of grouped database records in Yii2 using GridView widget and ActiveDataProvider. I'm trying to do that in this way:
$dpar = records::find()->select(['COUNT(*) as counts'])->
groupBy(['DATE(datetime)']);
$dataPpar = new ActiveDataProvider(['query' => $dpar]);
Query works fine, but then i can't display my data in GridView
<?= GridView::widget([
'dataProvider' => $dataPpar,
'columns' => [
'counts',
],
]);?>
All i receive is a correct (!!) number of rows with "not set" in every cell. Is there a way to solve it?
counts
as a parameter in your model?public $counts
. it seems your query is correct. can you put your data in response and database – mehri abbasi