I have a GridView::widget which is populated with this method:
StabilimentiController.php
public static function getGridColumns($isMine = true, $readonly = false) {
$c = [
'denominazione',
[
'attribute' => 'provincia',
'value' => 'indirizzo.provincia',
'headerOptions' => ['class' => 'table-col-provincia'],
'contentOptions' => ['class' => 'table-col-provincia'],
],
[
'attribute' => 'created_by',
'value' => 'azienda.ragioneSociale',
'headerOptions' => ['class' => 'table-col-createdBy'],
'contentOptions' => ['class' => 'table-col-createdBy'],
]
];
return $c;
}
I have some problems in creating a searchable inputBox for the field created_by.
Created_by
in my model is defined as integer, it's a code to identify univocally the company (azienda).
In my Stabilimenti.php
model I have this method to catch it and then with the .notation inside the getGridColumns method I can reach the ragioneSociale field that is the one I'm interested in.
/**
* @return \yii\db\ActiveQuery
*/
public function getAzienda() {
return $this->hasOne(Azienda::className(), ['id' => 'azienda_id'])->inverseOf('stabilimenti');
}
The ouput is what I want, the only problem is that the searchable field in my GridView take as input the int code and not the ragioneSociale
string, and is not very userFriendly.
In my StabilimentiSearch.php
public function rules(){
return [
[['id', 'azienda_id', 'created_by', 'updated_by'], 'integer'],
[['denominazione', 'indirizzo', 'citta', 'localita', 'provincia', 'cap', 'produttore', 'utente', 'azienda' ], 'safe'],
array('ragioneSociale', 'safe', 'on'=>'search'),
];
I put ragioneSociale
as safe and with the search option, but I've some difficulties in bind it correctly to the inputBox.