Sorting is not working on any column other than primary column in yii2 kartik grid

390 Views Asked by At

I have all set and filtering is working fine but facing problem in sorting columns When I set sort for id column it works fine but when I set other columns sort, it is not working

$dataProvider = new ActiveDataProvider([
        'query' => $query,

        'pagination' => [
            'pageSize' => 50,
        ],

    ]);

    $dataProvider->sort->attributes['id'] = [
            'asc' => ['challan.id' => SORT_ASC],
            'desc' => ['challan.id' => SORT_DESC],
        ];
        $dataProvider->sort->attributes['studentname'] = [
            'asc' => ['student.studentName' => SORT_ASC],
            'desc' => ['student.studentName' => SORT_DESC],
        ];
        $dataProvider->sort->attributes['sid'] = [
            'asc' => ['challan.sid' => SORT_ASC],
            'desc' => ['challan.sid' => SORT_DESC],
        ];

Please tell me what is wrong with this code Thanks in advance

1

There are 1 best solutions below

1
On

I have found the problem actually it is because I have used orderBy in $query variable

orderBy(['challan.id'=>SORT_DESC])