title: Sorting CSqlDataProvider in Yii
body: <p>I have a rather complex query, that I'm using CSqlDataProvider with:</p>
  
  <pre><code>        $sql = "
            SELECT  c.id AS id,
                    c.enabled AS enabled,
                    s.store_name AS store_name,
                    s.store_url AS store_url,
                    c.verified AS verified,
                    r.rating_total AS rating
            FROM compete_settings c
            LEFT JOIN stores s
              ON c.compete_id = s.id
            LEFT JOIN (
              (SELECT store_id, rating_total FROM amazon_sellers)
              UNION
              (SELECT store_id, rating_total FROM ebay_sellers)
            ) AS r
              ON c.compete_id = r.store_id
            WHERE c.store_id = :store_id
          ";
          $itemCount = Yii::app()-&gt;db-&gt;createCommand("SELECT COUNT(id) FROM compete_settings WHERE store_id = $store_id")-&gt;queryScalar();
          return new CSqlDataProvider($sql, array(
              'totalItemCount' =&gt; $itemCount,
              'params' =&gt; array(
                  'store_id' =&gt; $store_id,
              ),
              'sort' =&gt; array(
                  'attributes' =&gt; array ( 'enabled, store_name, rating' ),
                  'defaultOrder' =&gt; array('store_name'=&gt;false)
              ),
              'pagination' =&gt; array('pageSize' =&gt; Yii::app()-&gt;user-&gt;getState('pageSize_cs', Yii::app()-&gt;params['defaultPageSize']),),
          ));
  </code></pre>
  
  <p>The query works great. However, the columns are not sortable.</p>
  
  <p>I've made sure to follow <a href="https://stackoverflow.com/questions/13044681/yii-cgridview-sorting-with-csqldataprovider">Yii CGridview sorting with CSqlDataProvider</a>, but they are still not clickable column headers.</p>
  
  <p>Here are my column arrays:</p>
  
  <pre><code>'columns' =&gt; array(
      array(
          'header' =&gt; 'Enabled',
          'type'=&gt;'raw',
          'name'=&gt;'enabled',
          'htmlOptions'=&gt;array('class'=&gt;'enabled-column'),
          'value' =&gt; 'CHtml::checkbox("", $data["enabled"], array("id"=&gt;"c{$data[\'id\']}", "class"=&gt;"enable-switch"))',
      ),
      array(
          'header' =&gt; 'Name',
          'htmlOptions' =&gt; array('class' =&gt; 'account-name-column'),
          'type' =&gt; 'raw',
          'name'=&gt;'store_name',
      ),
      array(
          'header' =&gt; 'Store Rating',
          'name'=&gt;'rating',
      ),
  ),
  </code></pre>
  
  <p>Help? ):</p>