I have CGridView list names where I have a column that is a full name concatenated from a first name and last name (so the full name would have the form "John Smith"). However I want the column to be sortable on the last name. I have the following for sort in my model (as well as the virtual attribute declaration):
This only sorts full_name by the first character of full_name (the first name) however. Is there a way to do this without having to list the full name as "last_name, first_name" (ie Smith, John)?
Thanks, I’ve been searching and experimenting for hours and haven’t figured this one out.
I noticed that I had an older version of the attributes shown. Including both last_name and first_name in the sort attributes array resulted in it not sorting at all. The header acted as though it was sorting, but the names never changed order. With just last_name included in the sort attributes array (as shown below), it sorts on the first_name.
Based on your reassurance that it should work, I reviewed the name data in the database to check for blank spaces in front of names and found one (I was only using three names for testing). With that fixed everything works fine. I’m applying trim() to all input fields now!
I appreciate you taking the time to look at my code and letting me know it should work; that really helped me. My God, the time I’ve spent trying to figure out why this wasn’t working!