0Day Forums
How can I display a single record in 2 rows by using Yii CGridView? - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: FrameWork (https://0day.red/Forum-FrameWork)
+--- Thread: How can I display a single record in 2 rows by using Yii CGridView? (/Thread-How-can-I-display-a-single-record-in-2-rows-by-using-Yii-CGridView)



How can I display a single record in 2 rows by using Yii CGridView? - imbrue89379 - 07-20-2023

I am using CGridView in Yii, how can I display a single record in 2 lines?

Basically I want to show a record details in 1st row of table and on other row I want to display its summary, I tried it with div and css but can't get proper results, is anyone there who can help me in this case?

I am using like this:


<?php

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'bidding-grid',
'itemsCssClass' => 'data-default',
'dataProvider'=>$model,
'summaryText' => '',
'columns'=>array(
'people_detail_for_bid.Person' => array(
'type'=>'raw',
'name'=>'people_detail_for_bid.Person',
'value'=>'Yii::app()->Controller->createUserNameLink($data->people_detail_for_bid->PeopleFirstName." ".$data->people_detail_for_bid->PeopleLastName, $data->people_detail_for_bid->PeopleId).
"<br><span class=decriptionText>".$data->people_detail_for_bid->PeopleDesignation."</span>".
"<br><span class=decriptionText>".$data->people_detail_for_bid->PeopleEmail."</span>"',
'htmlOptions'=>array('width'=>200),
),
'timeAgo' => array(
'type'=>'raw',
'name'=>'timeAgo',
'value'=>'"<span class=decriptionText>".Yii::app()->Controller->_ago($data->PBPostedOn)."</sapn>"',
'htmlOptions'=>array('width'=>150),
),

),

));

?>






RE: How can I display a single record in 2 rows by using Yii CGridView? - overdrive169 - 07-20-2023

You can customize what you are rendering in the columns, so if you want to show two different fields of your table in the same row, you have to create a function in your model:

public function customColumn()
{
return $this->PeopleDesignation.'<br/>'.$this->PeopleEmail;
}

And then assign the method to the value of your column:

array(
'type'=>'html',
'value'=>'$data->customColumn()'
),

Cheers, Pablo.


RE: How can I display a single record in 2 rows by using Yii CGridView? - emersonvvjrnhqm - 07-20-2023

Sounds like 2 interleaved `CGridViews`. So you might try that, but I can't imagine it will work out well:

Overlay one `CGridView` over the other, with enough transparent space in each row for the other to display it's row, and ...

a. one `CGridView` table offset vertically by half a row height, *OR*
b. one table's row's text vertically top-aligned & the other bottom-aligned

But somehow I doubt that's a `CGridView` capability ;) And keeping the two in sync so they pagenate and scroll together would be darn near impossible. Sounds like you need to enhance CGridView or derive a new widget from `CGridView`. I wonder if JQuery has something to do this?


RE: How can I display a single record in 2 rows by using Yii CGridView? - claman183 - 07-20-2023

After too much search .. and I tried with different ways now finally got a solution for this .. that solution is basically a kind of 2nd way to do anything not actual way .. but it works to me ..

.....
.....

'timeAgo' => array(
'type'=>'raw',
'name'=>'timeAgo',
'value'=>'"<span class=decriptionText>".Yii::app()->Controller->_ago($data->PBPostedOn)."</sapn></td></tr><tr><td colspan=\"6\"><span class=decriptionText>".$data->PBSummary."</span>"',
'htmlOptions'=>array('width'=>150),
),

.....
.....


added some table tags on last column to close row and added another one.

hope it works for all ..

thanks ..


RE: How can I display a single record in 2 rows by using Yii CGridView? - shoppy148571 - 07-20-2023

I think the best and cleanest way to accomplish this is to create a new extension and extend it to CGridView, override the renderTableRow function like this:

/**
* Renders a table body row.
* @param integer $row the row number (zero-based).
*/
public function renderTableRow($row)
{
if($this->rowCssClassExpression!==null)
{
$data=$this->dataProvider->data[$row];
echo '<tr class="'.$this->evaluateExpression($this->rowCssClassExpression,array('row'=>$row,'data'=>$data)).'">';
}
else if(is_array($this->rowCssClass) && ($n=count($this->rowCssClass))>0)
echo '<tr class="'.$this->rowCssClass[$row%$n].'">';
else
echo '<tr>';

$colCtr = 0;
foreach($this->columns as $column){
$column->renderDataCell($row);
$colCtr++;
}

echo "</tr>\n";
echo "<tr><td colspan=\"$colCtr\">This is the summary row. </td></tr>";
}