CGridView filtering - yii does not search using the displayed content


I’m trying to display a CGridView list using the content taken from 2 tables - and I can do that without any issues - I made 2 models, set a relation, specified criteria, attributes, rules - and it works fine - the only problem I have is that when I add a column that should read the data from the joined table - it only displays it, but doesn’t filter using the specified value.

That’s my column:








“Owner” is an integer - it represents user’s id. I want to display user’s name from the table “user_info” that is stored in “name” column. CGridView lists up the user’s names, but filters using “owner” (integer). How can I change that? Trying to define “” or something similar in “name” field didn’t change anything.

All I want is to display the "name" field from joined "user_info" table and filter using the string "name" from "user_info" table. Any suggestions?

hope this wiki will help you


Thanks, that was really helpful. I made a mistake at first, but I fixed it and now it displays the correct list.

However - I still can’t get it to work.

Everything seems fine, but sorting does not sort using asc/desc order, it works more like "shuffling" the entries.

And - filtering doesn’t work as expected too - whenever I type part of any entry - it shows up every entry from database - but if I type a letter or string that does not occur in any result - the list generates no records at all. It works more like “if X occurs in any string from the table, show all results - if it does not occurs in any string from the table, show 0 results”. Any help would be appreciated.

// My mistake - I forgot to add "with" criteria to my CDbCriteria. Thanks again, yiqing95!

you are welcome :lol: the author of that wiki helps a lots .