Answer the question
In order to leave comments, you need to log in
How to make a group limit in yii2 ArrayDataProvider?
Good day.
There is a database
1 group=1
2 group=1
3 group=2
4 group=2
I need to display only 1 record from each group in the grid.
Now the whole thing is displayed with such a query
$query = TourTable::find()
->with(['user', 'profile', 'team'])
->where(['tour_id' => $tour_id]);
$dataProvider = new ArrayDataProvider([
'allModels' => $query->all(),
'pagination' => false,
'sort' => [
'defaultOrder' => ['group' => SORT_ASC, 'total' => '', 'difference' => ''],
'attributes' => [
'group',
'total',
'difference',
],
],
]);
Answer the question
In order to leave comments, you need to log in
$query = TourTable::find()
->with(['user', 'profile', 'team'])
->where(['tour_id' => $tour_id])
->groupBy('group');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question