M
M
Maxim Timofeev2016-04-17 18:50:09
Yii
Maxim Timofeev, 2016-04-17 18:50:09

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

1 answer(s)
A
Anton Natarov, 2016-04-17
@HanDroid

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, // сколько объектов на стр.
            ],
        ]);

Further, if orderBy is not enough for you, you can do Sort
$sort = new Sort([
            'attributes' => [
                'created_at' => [
                    'asc' => ['created_at' => SORT_ASC],
                    'desc' => ['created_at' => SORT_DESC],
                    'default' => SORT_DESC,
                    'label' => 'новизне',
                ],
            ],
        ]);

Sending from the controller to the view where you have the view sheet. I honestly don't remember how the view sheet works with arrays or objects. But in theory it should work.
return $this->render('index', [
            'yourSomeProvider' => $yourSomeProvider,
            'sort' => $sort,
        ]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question