Reputation:
Is it possible to sort using value not using column name?
For example,
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort'=> ['defaultOrder' => ['id' => 100]]
]);
I know i can easily do this with controller or adding params but i want to do it using search()
function.
By default, sorting works with column name, So, i am finding new workaround for sort by value.
Upvotes: 1
Views: 4498
Reputation: 133360
You can use setSort
$dataProvider->setSort([
'defaultOrder' => [ 'id' => SORT_ASC],
]);
otherwise your request is not satifisied this format because in not based on an array of column and order_type.
You can try override this setting the ->orderBy(' FIELD(id, '100', '300', '500')') ;
$dataProvider->query->orderBy(' FIELD(id, '100', '300', '500')')
Upvotes: 2