Vidhya
(Vidh Happy)
August 26, 2013, 4:09am
1
Hi,
I have listed the values of two tables in a Cgridview.
I would like to know how to group two or more rows which have same values in one column (Eg: To display a user belonging to multiple groups in a single row)
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-usergroup',
'dataProvider'=> UserGroup::model()->search(),
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
'selectableRows'=>'2',
),
'user.admin_userid',
array('name'=>'user.admin_user_name',
'value'=>'$data->user->username'),
'user.email',
'user.handphone',
array(
'name'=>'UserGroup.name',
'value' => '$data->UserGroup->username'
),
?>
Can anyone help me on how to achieve this?
Thanks & Regards,
Vidhya
Vidhya
(Vidh Happy)
August 26, 2013, 6:40am
3
Hi Rahul,
Thank you for your reply.
GroupGridView does not help me to group the entire rows based on two column values.
Say for eg: I have a grid view with the following columns:
username
2)Groupnames
3)Status
4)email
If I group based on username , then I get two rows for all other columns.
If I group based on username and status, I get most of the users combined.
But what I want is a single rows, which displays username, groupnames (separated by comma),status and email.
Kindly advice me on how to achieve the above.
Thanks & Regards,
Vidhya
traprajith
(Traprajith)
August 26, 2013, 10:07am
4
Group user with groupname
write a method username() on model
‘columns’=>array(
array(
'header'=>'username',
'value'=>array($model,'username'),
'sortable'=>true,
),
),
In model
public function username($data,$row)
{
$user = USER::model()->findAllByAttributes(array('groupname'=>$data->groupname));
if($user !=NULL)
{
//return username of all users as a string
}
else
{
return '-';
}
}
Vidhya
(Vidh Happy)
August 27, 2013, 8:34am
6
Hi Ranjith,
Thank you for your reply.
Could you please let me know if it is possible to display the categories in same row.
Thanks & Regards,
Vidhya
Vidhya
(Vidh Happy)
August 27, 2013, 10:01am
7
Hi Rahul,
I understood the flow.
But am getting the below error.
Could you please let me know where am going wrong?
Thanks & Regards,
Vidhya Prabha
Ankit_Modi
(Ankit Modi)
August 27, 2013, 10:43am
8
Hi,
you can change the function like .
for ex…
public function Showusernamedd()
{
$user_details = User::model()->findAll();
$dd_data = array();
if(isset($user_details) && !empty($user_details))
{
foreach($user_details AS $user)
{
$dd_data[$user->id] = $user->firstname.' '.$user->lastname.' ('.$user->username.') - '.$user->user_type;
}
}
return $dd_data;
}
traprajith
(Traprajith)
August 27, 2013, 11:01am
9
using findAll methods will result a 2d array. $user is a 2d array. use it according to your use.
traprajith
(Traprajith)
August 27, 2013, 11:03am
10
find categories in the function. and return as you wish. as comma separated ,as links etc…any thing.
Vidhya
(Vidh Happy)
September 3, 2013, 6:36am
11
Hi All,
Thank you so much for your help.
Thanks & Regards,
Vidhya