Dear All :
I create a table and below is my code about GridView
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'firstName',
],
[
'attribute' => 'lastName',
],
],
]); ?>
It can list the data and filter firstName or lastName in search input.
Here is my problem.
I save these two attributes into two columns in my database.
But!!!!! I want to show two values into one column in frontend.
Just like this :
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'firstName',
'value' => function () {
return $model->firstName.$model->lastName;
},
],
],
]); ?>
It’s fine in frontend, the list data will show the right value in grid form.
But the filter input can’t search value about the lastName, only the firstName can be searched.
I know because the query condition i wrote didn’t right.
$query->andFilterWhere(['like', 'firstName', $this->firstName])
->andFilterWhere(['like', 'lastName', $this->lastName]);
Is there any solution about merging two attributes into one cloumn and searching the correct value?
Please help. Thx!!!!!