Filters Not Appearing In Gridview

I am using Yii2 with the new GridView and I’m running into an issue. The GridView works fine and sorting works. The problem is with filtering. The row that should contain the filters is there but no text boxes appear. When I delete all of the columns, the text boxes will appear then.

Here is the code:


<?php

echo GridView::widget([

	'dataProvider' => $dataProvider,

	'filterModel' => $searchModel,

	'columns' => [

		'account',

		'profile',

		[

			'attribute' => 'groupPath',

			'value' => function ($data) {

				$ug = new UserGroups();

				$ug->groupPath = $data['groupPath'];

				$ug = $ug->getPretifyGroupPath();

				return $ug;

			},

		],

		[

			'attribute' => 'item',

			'value' => function ($data) {

				return '<a href="/items/'. $data['itemId'] .'" rel="item='. $data['itemId'] .'"> '. $data['itemName'] .'</a>';

			},

			'format' => 'raw',

			'filter' => true,

		],

		'quantity',

	]

]);

?>

Could you post some screen with and without that problem?

One thing I’ve noticed is: filters are not available/visible for columns that got in config option ‘value’ => function ($data), maybe I configured something wrong, but I think it’s like it should be.

Filters ‘works’ in database, not in PHP, so it would be hard to filter, because: in database is ‘gdan’ and in grid it shows ‘Gdansk’ [my function($data) translate it using external table in database], so how could database know what is ‘Gdansk’… there would be some function in config like ‘reverseValue => function($word)’ that translate value from grid to value in database [user type in filter ‘Gdansk’ and it search in database ‘gdan’], but that option could work only for some types of data.

If all filters (also for normal columns) disappear after you add any special column (with ‘value’) it’s serious problem, because for me all other columns work fine.

I believe you are correct. It isn’t working on the ‘value’ => function fields. I was able to get it to work on the other fields. So I guess the question is, how do I get it to work on those fields? I understand that the fields aren’t exactly pulling from the database but I would think that doing something like this in the model that it should work:

$query->andFilterWhere([‘like’, ‘itemName’ => $this->itemName]);

I was actually able to get this working with the value => function. Turns out my names weren’t consistent and that’s why it wasn’t working.