DikkiX
(DikkiX)
November 27, 2022, 8:40pm
1
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!
tri
(tri - Tommy Riboe)
November 27, 2022, 10:48pm
2
DikkiX
(DikkiX)
November 28, 2022, 6:09pm
3
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!
tri
(tri - Tommy Riboe)
November 28, 2022, 6:28pm
4
Try replacing attribute with value .
Or you can just use klanten.Klanten_klantennaam (like the other columns).
DikkiX
(DikkiX)
November 28, 2022, 6:33pm
5
Hi,
I have added both options but they show this.
.
tri
(tri - Tommy Riboe)
November 28, 2022, 6:44pm
6
What is the exact column name in the Klanten table?
DikkiX
(DikkiX)
November 28, 2022, 6:46pm
7
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”
tri
(tri - Tommy Riboe)
November 28, 2022, 6:55pm
8
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).
DikkiX
(DikkiX)
November 28, 2022, 7:03pm
9
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?
im in the code .
tri
(tri - Tommy Riboe)
November 28, 2022, 7:55pm
10
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)