title: Yii2 Gridview filtering a column that has Int data type based on varchar as inputed value
body: <p>I've an gridView for showing data. GridView table has a column that called as <strong>Created By</strong>, this column contain the <strong>ID</strong> of <strong>User</strong> that I get from <strong>user table</strong>. Basicly, this column will show data as Integer(ID) like this:</p>
  <p><a href="https://i.stack.imgur.com/UWMuE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UWMuE.png" alt="enter image description here" /></a></p>
  <p>But I've set code like this to show the <em>username</em> of the <em>ID</em>:</p>
  <pre><code>[
    'attribute' =&gt; 'created_by',
    'format' =&gt; 'raw',
    'value' =&gt; function ($data) {
                  $modelUser = Users::find()-&gt;where(['id' =&gt; $data-&gt;created_by])-&gt;one();
                  $nama = $modelUser-&gt;username;
                  return $nama;
              },
    'vAlign' =&gt; 'middle',
    'hAlign' =&gt; 'center',
  ],
  </code></pre>
  <p><strong>Result</strong>:</p>
  <p><a href="https://i.stack.imgur.com/41xLH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/41xLH.png" alt="enter image description here" /></a></p>
  <p>The gridView has filter column, I'm trying to filter data based on inserted value. I'm trying input username as the value for filtering but it give an error message &quot;<strong>created By must be an Integer</strong>&quot;, like this:</p>
  <p><a href="https://i.stack.imgur.com/tWMAH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tWMAH.png" alt="enter image description here" /></a></p>
  <h3>How do I can filtering that column using the a username(varchar)?</h3>
  <p>Thanks</p>
  <h2>Update</h2>
  <p>This is my <strong>searchModel.php</strong></p>
  <pre><code>&lt;?php
  
   namespace app\search;
  
   use Yii;
   use yii\base\Model;
   use yii\data\ActiveDataProvider;
   use app\models\Product;
  
   /**
   * ProductSearch represents the model behind the search form of `app\models\Product`.
   */
  class ProductSearch extends Product {
  
  /**
   * @inheritdoc
   */
  public function rules() {
      return [
          [['productId', 'userId', 'parentId', 'created_by'], 'integer'],
          [['date', 'created_at', 'name', 'address'], 'safe'],
          [['price'], 'number'],
      ];
  }
  
  /**
   * @inheritdoc
   */
  public function scenarios() {
      // bypass scenarios() implementation in the parent class
      return Model::scenarios();
  }
  
  /**
   * Creates data provider instance with search query applied
   *
   * @param array $params
   *
   * @return ActiveDataProvider
   */
  public function search($params) {
      $query = Product::find();
  
      // add conditions that should always apply here
  
      $dataProvider = new ActiveDataProvider([
          'query' =&gt; $query,
      ]);
  
      $this-&gt;load($params);
  
      if (!$this-&gt;validate()) {
          // uncomment the following line if you do not want to return any records when validation fails
          return $dataProvider;
      }
  
      // grid filtering conditions
      $query-&gt;andFilterWhere([
          'productId' =&gt; $this-&gt;productId,
          'price' =&gt; $this-&gt;price,
          'created_at' =&gt; $this-&gt;created_at,
          'created_by' =&gt; $this-&gt;created_by,
      ]);
  
      $query-&gt;andFilterWhere(['MONTH(date)' =&gt; $this-&gt;date])
              -&gt;andFilterWhere(['like', 'name', $this-&gt;name])
              -&gt;andFilterWhere(['like', 'address', $this-&gt;address]);
  
      return $dataProvider;
  }
  
  }
  </code></pre>