Answer the question
In order to leave comments, you need to log in
How to display N records in reverse order in Yii2 using ListView?
Good day!
Please tell me how to implement the output of the last 10 messages on the page so that the last message is displayed at the bottom, and the first of these 10 - at the beginning.
It is also required to load another 10 previous messages upon request.
Sorting is carried out by the date of creation of the message in the database.
controller:
$dataProvider = new ActiveDataProvider([
'query' => Message::find()->orderBy('created_at DESC'),
'pagination' => [
'pageSize' => 10,
],
]);
return $this->render('view', ['dataProvider' => $dataProvider]);
echo \yii\widgets\ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => '_message',
'layout' => "{items}",
]);
Answer the question
In order to leave comments, you need to log in
It seems to me that it is easier to solve this problem in js. Since playing with sorting in the dataProvider, you can get a very crutch solution and pagination that has gone wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question