Concatenated activerecord properties as a filter in GridView?

Hi folks,

I’ve done a fair bit of digging around both on here on and on google for an answer to this but to my surprise I have not been able to find one.

The thread title says it all, really - I want to have a concatenated string to display in my dropdown filter in GridView.

Here is that I have so far…

'filter' => Html::activeDropDownList($searchModel, 'competitor',


        Competition::find()->asArray()->all(), 'id', 'competitor_id'),

    ['class'=>'form-control','prompt' => 'Select']


So I would like to be able to populate with concatenated related data here - namely the competitor_last_name, competitor_first_name and competitor_number, which are in the Competitor table/model. The aim is to produce something like ‘Bloggs, Joe - 001’.

I thought this would be quite easy to do, but I can’t seem to find away to do it. Can anyone help?



So you just have to make an array like the following:


    id_1 => 'Bloggs, Joe - 001',

    id_2 => 'Some, Name - 002',

    id_3 => 'Other, Name - 003',



It’s very easy to make that kind of concatenated strings, isn’t it?