{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii/issues/3893","labels_url":"https://api.github.com/repos/yiisoft/yii/issues/3893/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii/issues/3893/comments","events_url":"https://api.github.com/repos/yiisoft/yii/issues/3893/events","html_url":"https://github.com/yiisoft/yii/issues/3893","id":89470764,"number":3893,"title":"CSort multi sort not working in version 1.1.16","user":{"login":"dashkhuu85","id":12380628,"avatar_url":"https://avatars.githubusercontent.com/u/12380628?v=3","gravatar_id":"","url":"https://api.github.com/users/dashkhuu85","html_url":"https://github.com/dashkhuu85","followers_url":"https://api.github.com/users/dashkhuu85/followers","following_url":"https://api.github.com/users/dashkhuu85/following{/other_user}","gists_url":"https://api.github.com/users/dashkhuu85/gists{/gist_id}","starred_url":"https://api.github.com/users/dashkhuu85/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dashkhuu85/subscriptions","organizations_url":"https://api.github.com/users/dashkhuu85/orgs","repos_url":"https://api.github.com/users/dashkhuu85/repos","events_url":"https://api.github.com/users/dashkhuu85/events{/privacy}","received_events_url":"https://api.github.com/users/dashkhuu85/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii/labels/status:to%20be%20verified","name":"status:to be verified","color":"fbca04"},{"url":"https://api.github.com/repos/yiisoft/yii/labels/type:bug","name":"type:bug","color":"e102d8"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-19T05:23:55Z","updated_at":"2015-10-16T18:41:14Z","closed_at":"2015-06-19T11:28:26Z","body":"Operating system: Windows 7 SP1\r\nWeb server: Xampp 5.6.8\r\nBrowser type: Google Chrome Version 43.0.2357.124 m\r\nYii version: 1.1.16\r\n\r\nWhen I use CSqlDataProvider in CGridview I enabled multisort true \r\n![in controller](https://cloud.githubusercontent.com/assets/12380628/8247472/2b956a9e-1684-11e5-89da-a75156df3ed5.png)\r\n\r\n\r\nthe initial grid with default sort order looks like this image\r\n![nosort](https://cloud.githubusercontent.com/assets/12380628/8247473/2b95ba8a-1684-11e5-99c3-407035d39092.png)\r\n\r\n\r\nif I sort with a single column (lets say Default)\r\n![sort by default asc](https://cloud.githubusercontent.com/assets/12380628/8247474/2b9627fe-1684-11e5-8390-026af8c80d9e.png)\r\nand multi sort with second column (let it be Title)\r\n![sort by default asc title asc](https://cloud.githubusercontent.com/assets/12380628/8247475/2b96187c-1684-11e5-8f1b-2259fe16f1e0.png)\r\nas you can see this just sorts with a single column (only with Title)\r\n\r\nBut if we swap the old direction with currently selected attributes sort order for array merge function in CSort file (Framework->Web->CSort.php => line 302)\r\nif($this->multiSort)\r\n\t$directions=array_merge(array($attribute=>$descending),$directions);\r\nelse\r\n\t$directions=array($attribute=>$descending);\r\nas below (the corrected one)\r\nif($this->multiSort)\r\n\t$directions=array_merge($directions,array($attribute=>$descending));\r\nelse\r\n\t$directions=array($attribute=>$descending);\r\nfixes the problem.\r\n![csort](https://cloud.githubusercontent.com/assets/12380628/8247471/2b94014a-1684-11e5-8908-7951db49f0a2.png)\r\n\r\nThe below image is correct on after swapping array merge arguments\r\n![sort by default asc title asc-correct](https://cloud.githubusercontent.com/assets/12380628/8247476/2b966584-1684-11e5-8fae-36913d1fc6a1.png)\r\n\r\nI think this should be corrected in further Yii releases.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii/issues/comments/148801601","html_url":"https://github.com/yiisoft/yii/issues/3893#issuecomment-148801601","issue_url":"https://api.github.com/repos/yiisoft/yii/issues/3893","id":148801601,"user":{"login":"cherifGsoul","id":109013,"avatar_url":"https://avatars.githubusercontent.com/u/109013?v=3","gravatar_id":"","url":"https://api.github.com/users/cherifGsoul","html_url":"https://github.com/cherifGsoul","followers_url":"https://api.github.com/users/cherifGsoul/followers","following_url":"https://api.github.com/users/cherifGsoul/following{/other_user}","gists_url":"https://api.github.com/users/cherifGsoul/gists{/gist_id}","starred_url":"https://api.github.com/users/cherifGsoul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cherifGsoul/subscriptions","organizations_url":"https://api.github.com/users/cherifGsoul/orgs","repos_url":"https://api.github.com/users/cherifGsoul/repos","events_url":"https://api.github.com/users/cherifGsoul/events{/privacy}","received_events_url":"https://api.github.com/users/cherifGsoul/received_events","type":"User","site_admin":false},"created_at":"2015-10-16T18:41:14Z","updated_at":"2015-10-16T18:41:14Z","body":"I have the same bug \r\n```php\r\nnew CActiveDataProvider($this, array(\r\n\t\t\t'criteria'=>$criteria,\r\n\t\t\t'sort'=>array(\r\n\t\t\t\t'multiSort'=>true,\r\n\t\t\t\t'sortVar'=>'sort',\r\n\t\t\t\t'separators'=>array(',','.'),\r\n\t\t\t\t'attributes'=>array('*')\r\n\t\t\t)\r\n\t\t));\r\n```\r\n\r\nIm on RESTful API when the url is like this:\r\n```\r\n/api/authors?sort=lastname.desc,firstname.asc\r\n```\r\nthe generated SQL:\r\n```sql\r\nSELECT * FROM `author` `t` \r\nWHERE (t.is_deleted=:isDeleted) \r\nAND (is_deleted=:ycp1) \r\nORDER BY `t`.`lastname` DESC \r\nLIMIT 10. Bound with :isDeleted=0, :ycp1='0')\r\n```\r\n\r\nIs this will be corrected?"}}