A
A
AlexRas2018-04-25 20:14:47
Yii
AlexRas, 2018-04-25 20:14:47

How to make such sorting in yii2 ActiveDataProvider?

Hello, tell me how you can make such sorting, it turns out reverse sorting ?sort=-id, only mirrored on the pages, example:

Страница 1:
8
9
10

Страница 2:
5
6
7

Страница 3:
2
3
4

Страница 4:
1

Interested in whether it is possible to do something in a simple way, maybe there is some kind of built-in feature, maybe someone will have ideas on how to implement it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-04-25
@AlexRas

Just pass the desired query to the dataProvider, with sort by id in reverse order, and then reverse the array ( php.net/manual/ru/function.array-reverse.php), which will give the getModels () method in activeDataProvider.
getModels() returns only the models for a particular page, so this is something you have to play with.
It's probably more beautiful to do this by creating your own DataProvider, inheriting from activeDataProvider and overriding getModels() there;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question