title: Yii2 - Gridview sorting using a model attribute
body: <p>In my model, i have tableName set to a database. I created a new attribute in the model called $fullname and defined it by joining with another table/model in my afterFind function like so:</p>
  
  <pre><code>public function afterFind()
  {
      parent::afterFind();
  
      $temp = Yii::$app-&gt;db-&gt;createCommand("select last_name || ', ' || first_name as fullname from employees where EMP_ID = :emp_id");
      $temp-&gt;bindValues([':emp_id' =&gt; $this-&gt;EMP_ID]);
      $this-&gt;fullname = $temp-&gt;queryColumn()[0];
  }
  </code></pre>
  
  <p>I am trying to figure out how I can use this model attribute in my gridview to sort by this fullname attribute.</p>
  
  <p>I have tried </p>
  
  <pre><code> $dataProvider-&gt;setSort([
      'attributes' =&gt; [
          'fullname' =&gt; [
              'asc' =&gt; ['fullname' =&gt; SORT_ASC],
              'desc' =&gt; ['fullname' =&gt; SORT_DESC],
              'label' =&gt; 'Full Name',
              'default' =&gt; SORT_ASC
          ]
      ]
      ]);
  </code></pre>
  
  <p>Can anyone tell me how I can sort by this attribute or an alternative to this solution?</p>