Relational Data Search in GridView

Hi all, I’m stuck at trying to make rational table cells searchable in GridView widget. Is there a simple way to do this?

I’ve found some tutorials, but they are all on yii1.

Here’s the structure example of what I have:

Clients:

clientid

name

Addresses:

addressid

address

client_id

1 Client can have many Addresses.

I’ve created them and generated the code with Gii and the relations are defined nicely in the models.

In the GridView I can access the Client name really easily like so:




[

'label' => 'Clients Name',

'value' => 'clients.name',  

],



But these fields are not searchable or sortable. I understand that I have to change the AddressSearch model, but I’m failing do do it successfully.

The image shows what it looks like. I want to make the "Klienta Vārds" and "Uzvārds" searchable.

Any help or pointing in the right direction appreciated :)

Thank you

Tutorial by Antonio Ramirez:

Displaying, Sorting and Filtering Model Relations on a GridView – Yii2:

http://www.ramirezcobos.com/2014/04/16/displaying-sorting-and-filtering-model-relations-on-a-gridview-yii2/

Thank you very much! That solves it! :)