title: yii2 display search filter and field from another table
body: <p>I have this in my controller departments class:</p>
  
  <p>Hello guys</p>
  
  <p>So there is something i am trying to achieve with yii</p>
  
  <p>I have a Departments table and a student table. Inside the students view i want to show the departments name and the filter. 
      While i am able to display the department name for each student but the department name filter doesn't show.</p>
  
  <p>Below is my code with comments:</p>
  
  <pre><code>/*Begining of Students model*/
  
  class Students extends \yii\db\ActiveRecord
  </code></pre>
  
  <p>/* this is where i did a reference to my students table*/</p>
  
  <pre><code>public function getDepartments()
  {
      return $this-&gt;hasMany(Departments::className(), ['department_id' =&gt; 'ID']);
  }
  </code></pre>
  
  <p>--- End of Students model</p>
  
  <p>--- Begining of Students View</p>
  
  <pre><code>/*Inside my view folder i have the Students folder where i have an index.php file where everything is listed in Gridview. */
  </code></pre>
  
  <p>View/Students/index.php</p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\grid\GridView;
  use yii\helpers\ArrayHelper;
  use app\models\States;
  use kartik\export\ExportMenu;
  
  /* @var $this yii\web\View */
  /* @var $searchModel app\models\AgentsSearch */
  /* @var $dataProvider yii\data\ActiveDataProvider */
  
  $this-&gt;title = 'Agents';
  $this-&gt;params['breadcrumbs'][] = $this-&gt;title;
  
  
  $gridColumns = [
      ['class' =&gt; 'yii\grid\SerialColumn'],
      'created_at',
      'name',
      departments.name',
      'status',
      ['class' =&gt; 'yii\grid\ActionColumn'],
  
  ];
  
  
  // Renders a export dropdown menu
  echo ExportMenu::widget([
      'dataProvider' =&gt; $dataProvider,
      'columns' =&gt; $gridColumns
  ]);
  
      ?&gt;
      &lt;?= GridView::widget([
          'dataProvider' =&gt; $dataProvider,
          'tableOptions' =&gt;['class'=&gt;'table table-bordered'], 
          'filterModel' =&gt; $searchModel,
          'columns' =&gt; $gridColumns
      ]); ?&gt;
  &lt;/div&gt;
  
  
  
  /*End of Students view*/
  
  
  
  /*Begining of Students search.*/
  
  
  /*models/StudentsSearch.php*/
  </code></pre>
  
  <p>I understand that the code below inside my StudentsSearch.php file is responsible for displaying the filter for each field.</p>
  
  <pre><code>  public function rules()
      {
          return [
              [['phone'], 'integer'],
              //my understanding is that this is what controls the filter form, only fields listed here have filters
              [['phone','name' 'email', 'address','city','departments.name'], 'safe'],
          ];
      }
  
  /*End of Students search.*/
  </code></pre>
  
  <p>I am able to show filter for every other thing but how do i show filter for the department name?</p>