A
A
Artur Kosikov2018-11-14 22:09:05
Yii
Artur Kosikov, 2018-11-14 22:09:05

Why doesn't sorting by numeric field work in ActiveDataProvider?

$dataProvider = new ActiveDataProvider([
      'query' => $query,
      'sort' => [
          'attributes' => ['id','name']
      ],
      'pagination' => [ 'pageSize' => 20 ]
    ]);

And in the form:
<?= GridView::widget([
  'dataProvider' => $dataProvider ...

As a result, sorting by name works, but not by ID. Actually, I tried with other numeric fields - it doesn’t sort numbers ... :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artur Kosikov, 2018-11-14
@atillus

Understood.
I messed it up :)
In the $query itself I did:
$query = Shops::find()->orderBy('name');

D
Dmitry, 2018-11-14
@slo_nik

Good evening.
Try like this

'sort' => [
          'defaultOrder' => [
             'id' => SORT_DESC,
            'name' => SORT_DESC
           ]
      ],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question