jkofsky
(Jkofsky)
December 22, 2010, 9:18pm
1
I am manually displaying info from a CActiveDataProvider. I want to get the odd/even class rendered for the row in a renderPartial() call. Can anyone help?
in view file:
$idx=0;
$hdrProtocol;
foreach($dp as $row) {
if($row->Protocol != $hdrProtocol) {
echoHeader($row);
$hdrProtocol = $row->Protocol;
} //EndIf
++$idx;
$this->renderPartial('_publicIP',$row);
} //Next $row
in partial _view file:
<?php $class = ($idx%2)? 'odd' :'even'; ?>
<tr class="<?php echo $class ?>">
<td><?php echo CHtml::encode($data->Purpose); ?></td>
<td><?php echo CHtml::encode($data->Location); ?></td>
<td><?php echo CHtml::encode($data->Address); ?></td>
<td><?php echo CHtml::encode($data->Pswrd); ?></td>
</tr>
gusnips
(Gustavo)
December 23, 2010, 1:07am
2
replace
$this->renderPartial('_publicIP',$row);
for
$this->renderPartial('_publicIP',array('data'=>$row,'rowNumber'=>$idx));
replace
$this->renderPartial('_publicIP',$row);
for
$this->renderPartial('_publicIP',array('data'=>$row,'rowNumber'=>$idx));
very close was
$this->renderPartial('_publicIP',array('data'=>$row,'idx'=>$idx));
and you can actually
view:
$class='';
$idx=0;
$hdrProtocol;
foreach($dp as $row) {
if($row->Protocol != $hdrProtocol) {
echoHeader($row);
$hdrProtocol = $row->Protocol;
} //EndIf
$class = (++$idx%2)? 'odd' :'even';
$this->renderPartial('_publicIP',array('data'=>$row,'class'=>$class));
} //Next $row
partial:
<tr class="<?php echo $class ?>">
<td><?php echo CHtml::encode($data->Purpose); ?></td>
<td><?php echo CHtml::encode($data->Location); ?></td>
<td><?php echo CHtml::encode($data->Address); ?></td>
<td><?php echo CHtml::encode($data->Pswrd); ?></td>
</tr>
jkofsky
(Jkofsky)
December 23, 2010, 6:11pm
4
Very cool. I knew it was something simple. I liked/used Antonio’s idea. Thank you all.