title: Yii Sortable Column in CGridView
body: <p>I have a calculated column I wanna have sortable.
  I have a get method for it...</p>
  
  <pre><code>public function getCur_margin() {
          return number_format(($this-&gt;store_cost / $this-&gt;store_price) / $this-&gt;store_cost * 100, 2) . '%';
      }
  </code></pre>
  
  <p>And I followed this thread...</p>
  
  <p><a href="https://stackoverflow.com/questions/7633516/cgridview-custom-field-sortable">CGridview custom field sortable</a></p>
  
  <p>But now it's looking for an actual column in the database. How can I fetch a field using <code>&lt;calculations&gt; AS cur_margin</code> only temporarily for this CActiveDataProvider?</p>
  
  <p>Here is the controller code for the provider:</p>
  
  <pre><code>$dataProvider = new CActiveDataProvider('Products', array(
      'criteria' =&gt; array(
          'condition' =&gt; 'store_id IN (SELECT `id` FROM `stores` WHERE `user_id` = ' . Yii::app()-&gt;user-&gt;id . ')',
      ),
      'pagination' =&gt; array(
          'pageSize' =&gt; 15,
      ),
      'sort'=&gt;array(
          'attributes'=&gt;array(
              'cur_margin' =&gt; array(
                  'asc' =&gt; 'cur_margin ASC',
                  'desc' =&gt; 'cur_margin DESC',
              ),
          ),
      ),
  ));
  </code></pre>