Answer the question
In order to leave comments, you need to log in
How to customize ListView sorting through Sort in Yii2?
Hello. I have the following problem.
In the controller, I set the dataProvider and an instance of the Sort class:
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$sort = new Sort([
'attributes' => [
'id' => [
'default' => SORT_ASC,
],
'price' => [
'desc' => ['lp.price' => SORT_DESC],
'asc' => ['lp.price' => SORT_ASC],
'label' => 'Цена'
],
],
]);
echo Dropdown::widget([
'items' => [
Html::tag('li', $sort->link('price'), ['class' => 'sort-results__dropdown-item']),
],
'options' => ['class' => 'sort-results__dropdown']
]);
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => '_list',
'pager' => [
'class' => '\app\components\LinkPager',
'hideOnSinglePage' => false,
'maxButtonCount' => 3,
'prevFivePageLabel' => true,
'nextFivePageLabel' => true,
'lastPageLabel' => true,
'firstPageLabel' => true
],
'layout' => "{items}\n{pager}",
'emptyText' => '',
]); ?>
'sorter' => $sort,
, it did not help. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question