Answer the question
In order to leave comments, you need to log in
How to sort dataProvider from _search file with ActiveForm in Yii2?
Good afternoon.
In my _search file I have a set for filtering the dataProvider in the ListView :
<?php $form = ActiveForm::begin([
'options' => ['data-pjax' => true ],
'method' => 'post',
]); ?>
<?= $form->field($model, 'id')->textInput([
'type'=>'number'
]) ?>
<!-- рабочий price filter -->
<?= $form->field($model, 'name')->textInput() ?>
<?php ActiveForm::end(); ?>
Answer the question
In order to leave comments, you need to log in
Sorting is configured via the sort property date of the provider
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort'=> [
'attributes' => [
'age',
'name' => [
'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC],
'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC],
'default' => SORT_DESC,
'label' => 'Name',
],
],
]);
Already the de facto standard for sorting is clicking on the column heading. Why don't you like it out of the box? Why all these crutches with an extra select box?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question