J
J
justyork2013-11-14 09:09:22
Yii
justyork, 2013-11-14 09:09:22

Correct output through CGridView and the right data from CActiveDataProvider?

Hello everyone, I need advice on these two things.
1. CGridView.
I need to make not one line but 2 in the table that it forms, since there is a lot of data, I tried various perversions with js and Html and settled on this option.

array(
            'headerHtmlOptions' => array(
                'style' => 'display: none'
            ),
            'filterHtmlOptions' => array(
                'style' => 'display: none'
            ),
            'htmlOptions' => array(
                'style' => 'display: none'
            ),
            'value' => array($this, 'gridPropertyData'),
),

made a method in the controller,
public function gridPropertyData($data, $row){
        return $this->renderPartial("//common/property_info", array("data" => $data), false);
}

which generates the html I need, and in the view at the very beginning I close the open tr and so on:
</td></tr><tr>
and then I write everything I need. How perverted is this and can it be done more correctly?
2. CActiveDataProvider.
I need the search to be by the value of the associated table
, I assumed that it should be done like this, but it does not work.
$criteria->compare('city',$this->_city->name);

There is a connection, of course.
I guess there is more to do here:
return new CActiveDataProvider($this, array(
  'criteria'=>$criteria,        
));

But here's what, without a clue, tell me at least where to dig.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
LastDragon, 2013-11-14
@justyork

1. Only by extending the class CGridViewand overriding the methodrenderTableRow()

2. See http://www.yiiframework.com/doc/guide/1.1/en/database.arr


$criteria=new CDbCriteria();
$criteria->with = ['city']; // название отношения, используется как префикс
$criteria->compare('city.name', $this->_city->name);
...

J
justyork, 2013-11-14
@justyork

Model

$criteria->with = ['_city'];
$criteria->compare('_city.name', $this->_city->name);

Grid

array(
    'name'=>'_city.name', 
)

Question: the norms are displayed, but now how to fasten the search so that it works like the rest on Ajax and sorting, because only the Name is displayed in th, without links, can I screw it manually through the header or is there a way?

K
Konstantin Shirkin, 2014-01-27
@skw85

Sorting:

$dataProvider=new CActiveDataProvider('Model', array(
    'Sort'=>array(
        'defaultOrder'=>'t.id DESC',
        'attributes'=>array(
            'CityName'=>array(
                'asc'=>'_city.name',
                'desc'=>'_city.name DESC',
                'label'=>'Город,
                'default'=>'asc',
             ),
            '*',
       ),
            ),

And already in the grid (sheet) itself, you specify this field in sorting:
...
        'sortableAttributes'=>array(
            ...
            'CityName',
            ...
        ),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question