groupgridview

This extension allows to group data in your grid
78 followers

GroupGridView extends CGridView with following features:

  • group equal values in merged cells
  • add extra rows for grouped values

Links

Requirements

Developed and tested on Yii 1.1.9.

Installation

Put groupgridview folder from zip to your protected/extensions.

Usage

See code samples in demo.

Main parameters are:

  • mergeColumns - array of columns in which equal cells to be merged
  • mergeType - how merge is displayed:

    • simple: column values are merged independently (default)
    • nested: column values are merged if at least one value of nested columns changes (makes sense when several columns in $mergeColumns option, see #11462)
    • firstrow: column values are merged independently, but value is shown in first row of group and below cells just cleared (instead of rowspan)
  • extraRowColumns - array of columns for which every change of value will trigger extra row

  • extraRowPos - position of extra row relative to group: above (default) | below
  • extraRowExpression - string PHP expression or function that returns value displayed in extrarow. Can use $data and $totals inside.
  • extraRowTotals - function that is used to calc subtotals. Example:
'extraRowTotals' => function($data, $row, &$totals) {
     if(!isset($totals['sum_age'])) $totals['sum_age'] = 0;
     $totals['sum_age'] += $data['age'];
}

Variable $totals is available in extraRowExpression.
Please consider that subtotals are incorrect when used together with pagination!

Usage with Twitter Bootstrap

You can use it with bootstrap gridview via ext.groupgridview.BootGroupGridView widget.
Since 1.2 you need Yii-bootstrap 1.0 and above.

Note

Extension uses only data that are on current grid page. You should take care about sorting to get correct results.

Total 20 comments

#12698 report it
Vitalets at 2013/04/06 06:58am
Re: CHtml::link

@hiral darji

It seems links are not grouped because they have different URLs (due to different "id"=>$data->hostel_room_category_facility_id). And that is correct. Otherwise, if they merged you will loss some urls from your grid. You can try without id - it should work:

array(
                'name'=>'room_category_name',
                'type'=>'raw',
              'value'=>'CHtml::link($data->Rel_hostel_room_category->room_category_name,array("hostelRoomCategoryFacility/update"))',
        ),
#12680 report it
hiral darji at 2013/04/05 02:46am
RE: Vitalets

this is my code

$this->widget('ext.groupgridview.GroupGridView', array(
      'id' => 'hostel-room-category-facility-grid',
      'dataProvider' => $dataProvider,
      'mergeColumns' => ('room_category_name'),
      'filter'=>$model,
      'columns' => array(
       array(
        'header'=>'SN.',
        'class'=>'IndexColumn',
        ),
        //'hostel_room_category_facility_id',
 
        array(
                'name'=>'room_category_name',
                'type'=>'raw',
                'value'=>'CHtml::link($data->Rel_hostel_room_category->room_category_name,array("hostelRoomCategoryFacility/update","id"=>$data->hostel_room_category_facility_id))',
        ), 
 
        array(
                'name'=>'facility_name',
              //  'type'=>'raw',        
                'value'=> '$data->Rel_hostel_room_facility->facility_name',
              ),
        array(
                'name'=>'room_category_facility_start_date',
                //'type'=>'raw',        
                'value'=>'date_format(new DateTime($data->room_category_facility_start_date), "d-m-Y")',
            ),
 
        array(
                'name'=>'room_category_facility_end_date',      
                'value'=>'($data->room_category_facility_end_date == NULL) ? "Not Set" : date_format(new DateTime($data->room_category_facility_end_date),"d-m-Y")',
            ),
 
        array('name'=>'Organization',
            'value'=>'Organization::model()->findByPk($data->hostel_room_category_facility_organization_id)->organization_name',
            'filter' => false,
        ),
        array(
            'class'=>'CButtonColumn',
        ),
    ),
    'pager'=>array(
        'class'=>'AjaxList',
        'maxButtonCount'=>$model->count(),
//      'maxButtonCount'=>25,
        'header'=>''
      ),
));

this is my code for grideview in this i want to group room_category_name field but with link it is not group. without link its work fine.

#12624 report it
Vitalets at 2013/04/02 03:11am
Re: data provider & CHtml::link

@Bluenica
To have model1 in extrarow and model2 in content rows I think you should combine two dataproviders into single one. And then use it in groupgridview. Otherwise grid will not understand when exactly to insert extrarows.

@hiral darji
Could you show the your code snippet ?

#12622 report it
hiral darji at 2013/04/02 02:54am
group columns when its value has CHtml::link

hello all,

I have trouble with groupgridview when i merge the column which value has CHtml::link, mergeColumns not work at that time for me.

Reply me as soon as possible.

Thanks in advance.

#12566 report it
Bluenica at 2013/03/29 03:47am
data provider

hello i was wondering if 'extraRowColumns' => array('name'), can also be a dataprovider? is this extension possible for different models?

i have model1 and model2.

I need the model1 to be in the extraRowColumns and model2 as the content of the extraRowColumns.

they're both being passed in my view as dataprovider

#11945 report it
junaidatari at 2013/02/14 03:05pm
You are the Man!

great work.. you saved my life :D

echo "Thank You ~Vitalets~";
#11790 report it
Vitalets at 2013/02/04 06:30am
Re: Hierarchical merge

Hi, Daniel,

I found that it is controlled by mergeType option that was not documented. Please try to set

'mergeType' => 'nested',

I will update docs.

#11783 report it
Daniel at 2013/02/03 10:06pm
Re: Hierarchical merge

Hi Vitalets,

still not working, I change the order, but resulting the same.

either

'mergeColumns' => array('location', 'transDate'),

or

'mergeColumns' => array('transDate', 'location'),

results are the same.

#11636 report it
Vitalets at 2013/01/24 05:47am
Re: column group in heading

hi, not possible now. But could be good feature!

#11635 report it
horizons at 2013/01/24 04:26am
column group in heading

Is it somehow possible to generate Tables like this? With a grouped heading above some defined columns.

Col A  | Group Heading   | Col D 
       | Col B  | Col C  |       
---------------------------------
A123   | bbb    | c123   | d123  
---------------------------------
A123   | bbb    | c456   | d123  
---------------------------------
A456   | bbb    | c999   | d123  
---------------------------------
A456   | bbb    | c888   | d123  
---------------------------------
A456   | bzz    | c777   | d123
#11466 report it
Vitalets at 2013/01/15 06:42am
Re: Hierarchical merge

I assume it should already work exactly this way..
Could you re-check the order of columns in mergeColumns?

'mergeColumns' => array('col A', 'col B'), //not array('col B', 'col A')
#11464 report it
Daniel at 2013/01/15 03:15am
Re: Hierarchical merge

see the updated third example.

My point is that "bbb" is split up for "A123" and "A456". not merge since the first "bbb" is belong to "A123" and second one is belong to "A456".

What I need is that "bbb" that is merged only if it has same "A123" see example 2.

Thank you for quick support. Anyway, this is great extension and really useful.

#11463 report it
Vitalets at 2013/01/15 03:00am
Re: Hierarchical merge

hi, is't it this ?
or please fix formatting in your third sample..

#11462 report it
Daniel at 2013/01/15 12:37am
Hierarchical merge

Hi,

I was wondering is that possible to merge hierarchically? For example

Col A  | Col B  | Col C
-----------------------
A123   | bbb    | c123
-----------------------
A123   | bbb    | c456
-----------------------
A456   | bbb    | c999
-----------------------
A456   | bbb    | c888
-----------------------
A456   | bzz    | c777

merge to be

Col A  | Col B  | Col C
-----------------------
       |        | c123
A123   | bbb    |------
       |        | c456
-------|---------------
       |        | c999
       | bbb    |------
A456   |        | c888
       |--------|------
       | bzz    | c777

not

Col A  | Col B  | Col C
-----------------------
       |        | c123
A123   |        |------
       |        | c456
-------| bbb    |------
       |        | c999
       |        |------
A456   |        | c888
       |--------|------
       | bzz    | c777

because I will mixed up the hierarchical process.

Thank you.

#10848 report it
Vitalets at 2012/11/27 09:19am
Re: can it be exported to excel/pdf?

Hi,

Can I export the groupgridview to excel/pdf?
no. I think it's should be another extension that converts any CGridView 2 pdf(no matter with grouped cells or not).

Can I paginate the gridview so that the merge column is displayed in one page?
currently no. It would be great improvement of extension. But it seems not easy: now it is grouping data already fetched from database, and in you request extension should generate sql to fetch all rows for particular group (if I understand you right). You can have a look on source on github and may be find a pretty solution.

#10835 report it
Daniel at 2012/11/26 09:59pm
can it be exported to excel/pdf?

Hi,

Can I export the groupgridview to excel/pdf?

Can I paginate the gridview so that the merge column is displayed in one page?

Thank you for your help.

Cheers,

Daniel

#10671 report it
hyde82 at 2012/11/13 11:33am
Great!

great extension!!

#9396 report it
Vitalets at 2012/08/08 02:20pm
Re: snippets

hi fr0d0z,

please see demo, there are plenty of example snippets there

#9067 report it
Vitalets at 2012/07/17 02:23pm
RE: Demo site down

demo site is online!

#9059 report it
Vitalets at 2012/07/17 05:42am
RE: Demo site down

yes, thank you, I also got notification from hosting. Checking..

Leave a comment

Please to leave your comment.

Create extension