Display Foreign key name, instead of ID

Hi there Again,

I have a quick question.
I have a foreign key link from “Klanten_id” to my Klanten tabel “ID” in my Overzicht Table.
Now the the gridview on my Overzicht index shows the id, but I want it to show the name that is linked to the chosen “ID”

I will show screenshots to make it easier to understand!

But i want it to show this on Overzicht.


That would be “Klanten.klantennaam” that has the “Klanten_ID 1”

If anyone can help me would be highly appreciated.
Excuses for the bad english!

https://forum.yiiframework.com/t/showing-relational-data-in-gridview/85792

Hi,

i have tried what u sent me and im doing something wrong.
This is my relation


and this is my gridview.

I know that im doing something wrong, just not what.

Hopefully u can enlighten me!

Try replacing attribute with value.
Or you can just use klanten.Klanten_klantennaam (like the other columns).

Hi,

I have added both options but they show this.

.

What is the exact column name in the Klanten table?

image

And the foreignkey link is Klanten_id but i dont want it to show the id in de index but the Name that has that is linked to the “klanten_id”

So with this method you should use klanten.klantennaam

(I don’t remember the exact characteristics of using foreign key defined in the db and I wont look it up today).

Thank you, it worked!!

But do u know how i give the option to also be able to searchfilter. for the name in the gridview as the rest?
image

im in the code .

A little bit more complex.

Perhaps this post can help
https://forum.yiiframework.com/t/export-gridview-data-to-csv/134532/4?u=tri

This goes into the search model search()
joinWith() the relation.
add sort attributes (use table name not relation name)
(in case of computed fields, add attribute to search model)