A
A
agent11562017-01-25 10:43:38
Yii
agent1156, 2017-01-25 10:43:38

How to change GridView output in admin panel to DESC by Id?

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'id',
            'category',
            'title_ru',
            //'title_en',
           // 'title_ir',
            // 'text_ru:html',
            // 'text_en:ntext',
            // 'text_ir:ntext',
            // 'img',
             'date',
             //'conclusion_top',
            ['attribute' => 'conclusion_top',
            'value' => function($data){
                return $data-> conclusion_top ? '<span class="text-success"><i class="glyphicon glyphicon-ok"></i></span>' : '<span class="text-danger"><i class=" glyphicon glyphicon-remove"></i></span>' ;
            },
            'format'=> 'raw'],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pozdnyakov, 2017-01-25
@Afinogen

In the search model

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question