How to search on grid view which has relation

Can someone give an example on how to search record with city name, for example city_id is a foreign key. Instead of searching with the value of city_id(FK) in grid view , it should be search with "city name".

This was asked yesterday(?), so instead of reiterating, let’s link to the topic instead:

Topic ;)

im unable to use with this code






its not applying conditions

but im able to retrieve with following code is it correct and pls help me how to use with ‘search_location’






You lost me …

But, put this in your search function:

$criteria->compare('name', $this->city_id);

You may have to change it if ‘name’ conflicts.

In that case you should put the relation name in front of it:

I have added that in my search function im able to search , but that’s not my question sir i want to use variable search_location that im unable to do with that im able to with cat_id please see that code.

I think you can use it by setting the column type to ‘raw’, ie:

			'name' => 'search_location',


But I am not sure if that will enable search on that column.