Enthu
(Zackrocha14)
September 22, 2014, 10:00am
1
Hi Yii users,
I am currently facing a problem displaying 3 data from different columns of the same table.
------Start of code-------
array(
'name' => 'packing_size_1',
'type' => 'raw',
'value' => 'CHtml::encode($data["packing_size_1"])',
'filter' => CHtml::activeTextField($model, 'packing_size_1', array('class'=>'form-control form-filter input-sm')),
),
array(
'name' => 'packing_size_2',
'type' => 'raw',
'value' => 'CHtml::encode($data["packing_size_2"])',
'filter' => CHtml::activeTextField($model, 'packing_size_2', array('class'=>'form-control form-filter input-sm')),
),
array(
'name' => 'packing_size_3',
'type' => 'raw',
'value' => 'CHtml::encode($data["packing_size_3"])',
'filter' => CHtml::activeTextField($model, 'packing_size_3', array('class'=>'form-control form-filter input-sm')),
),
------end of code-------
As the above code renders three columns on front view, can any user guide me on the possibility on displaying the data in one column? I understand the need to make it searchable, how do I go about it?
Thank you.
softark
(Softark)
September 22, 2014, 12:13pm
2
I would create a virtual attribute, say, "packing_size_123" for it.
Hopefully we’ll be able to construct some SELECT clause to get it from “packing_size_1”, “packing_size_2” and “packing_size_3”, and some WHERE clause to search them from it … assuming you are using CSqlDataProvider.
Hi;
I hope below example will solve ur issues
In controller
u have to write method like below
protected function gridPacking($data,$row) {
return CHtml::encode($data->packing_size_1) .' / ' . CHtml::encode($data->packing_size_2).' / ' . CHtml::encode($data->packing_size_3);
}
In view
u have to write method like below
'value'=>$this->grid->controller->gridPacking($data)
Enthu
(Zackrocha14)
September 23, 2014, 1:44am
4
Hi;
I hope below example will solve ur issues
In controller
u have to write method like below
protected function gridPacking($data,$row) {
return CHtml::encode($data->packing_size_1) .' / ' . CHtml::encode($data->packing_size_2).' / ' . CHtml::encode($data->packing_size_3);
}
In view
u have to write method like below
'value'=>$this->grid->controller->gridPacking($data)
It returns me an error - Property "StockController.grid" is not defined.
Am I missing something?
Thank you.
ok thats fine…
please try to access controller in view page. then u can access that method.
our intension is just get the constructed content from controller and display in view
Inside the view script, we can access the controller instance using $this. We can thus pull in any property of the controller by evaluating $this->propertyName in the view.
Enthu
(Zackrocha14)
September 23, 2014, 10:39am
6
ok thats fine…
please try to access controller in view page. then u can access that method.
our intension is just get the constructed content from controller and display in view
Inside the view script, we can access the controller instance using $this. We can thus pull in any property of the controller by evaluating $this->propertyName in the view.
Hi Chandran,
Let me give it a go and update this thread accordingly.
Million thanks for the assistance.
Thank you.