Looking at this article http://www.yiiframework.com/doc/api/1.1/CSort
It shows that you can sort columns that are a 'virtial'
In my GridView I have
'columns' => [
[
'label' => 'Name',
'attribute' => 'displaynamehtml',
'format' => 'raw'
],
'displaynameashtml' is an attribute that combines a first_name and last_name and creates a clickable URL.
To sort this I have:
$dataProvider->setSort([
'attributes' => [
'displaynamehtml' => [
'asc' => 'first_name, last_name',
'desc' => 'first_name DESC, last_name DESC',
'label' => 'Name'
],
However this does not work and gives me the error 'Invalid argument supplied for foreach()'
Any ideas what is wrong?
Try something like
$dataProvider->setSort([
'attributes' => [
'displaynamehtml' => [
'asc' => [
'first_name' => SORT_ASC,
'last_name' => SORT_ASC,
],
'desc' => [
'first_name' => SORT_DESC,
'last_name' => SORT_DESC,
],
'label' => 'Name'
],
I suggest a little different:
$dataProvider->sort->attributes['displaynamehtml'] = [
'asc' => [
'first_name' => SORT_ASC,
'last_name' => SORT_ASC,
],
'desc' => [
'first_name' => SORT_DESC,
'last_name' => SORT_DESC,
],
];
Put this in the model search