Answer the question
In order to leave comments, you need to log in
How to determine the record closest by date in yii2 and determine its place in pagination?
How to determine the record closest by date in yii2 and determine its place in pagination?
Let's say there is a table with events that have a start date. I plan to display everything (ListView), but the pagination should initially be on the page where the next date in the future.
How many options I do not sort out in my head - everything is "shit code". Stuck. Need a hint.
Answer the question
In order to leave comments, you need to log in
And what is the difficulty? create a data provider, make a request sorted by date. Specify how many lines in the view sheet you need and after how many to create pagination
$someQuery = Category::find()->where(['status' => Coupon::STATUS_NEW])->orderby('create_at');
$yourSomeProvide r= new ActiveDataProvider([
'query' => $someQuery,
'pagination' => [
'pageSize' => 8, // сколько объектов на стр.
],
]);
$sort = new Sort([
'attributes' => [
'created_at' => [
'asc' => ['created_at' => SORT_ASC],
'desc' => ['created_at' => SORT_DESC],
'default' => SORT_DESC,
'label' => 'новизне',
],
],
]);
return $this->render('index', [
'yourSomeProvider' => $yourSomeProvider,
'sort' => $sort,
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question