Answer the question
In order to leave comments, you need to log in
Can the ActiveDataProvider be configured to sort by the string length of a particular field?
I use GridView together with ActiveDataProvider. When displaying a table, it is necessary to configure sorting: by the length of the strings of values of a certain field.
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'name' => ???
]
]
]);
Answer the question
In order to leave comments, you need to log in
something like this
$dataProvider->sort->attributes['name'] = [
'asc' => [
'LENGTH(name)' => SORT_ASC
],
'desc' => [
'LENGTH(name)' => SORT_DESC
],
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question