YII2 Sorting and Searching with a Junction Table Column (Many to Many Relationship)

I have studied the tutorial of yii and it works (Tutorial)!

But if I have a table with all properties… For example

tblcontactsproperties:
- contact_id
- propertie_name
- propertie_value

In the grid I can access the data without any problems:

value' => function($model) {
                    $datareturn = $model->getContactsProperties()
                        ->where(['=', 'propertie_name', 'age'])
                        ->one();

                    return  $datareturn['propertie_value'];
                    },

            ], 

How can I extend the search model?

public function search($params)
{
     $query = Contacts::find()->innerJoinWith('ContactsProperties', true);
     //!!!WRONG!!!
...

This causes all properties to be counted. Only one row is displayed in the grid.

I only want to filter and search selected properties (e.g. age).