Krajee

Group Grid Demo #6

Thankful to Krajee! BUY A COFFEEor to get more out of us.

An example combining example # 3 (grouped row header) with example # 4 (group footer). Note that you must carefully set mergeColumns setting in groupFooter or groupHeader for such a scenario (or skip this setting if not needed). In this case when you set groupedRow to true, a complete grid column will be removed and displayed as a group row. Hence the column indices in the group columns MUST NOT start with the removed column. If you are not clear, you may skip setting mergeColumns to ensure the markup is not broken, and work out from there which columns can be merged.



Tip

Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)

Total 77 items.
Grid Grouping Example 6
#SupplierCategoryProduct NameUnit PriceUnits In StockAmount In Stock
 
 
1Forts d'rablesCondimentsSirop d'rable28.501133,220.50
2Forts d'rablesConfectionsTarte au sucre49.3017838.10
3Gai pturageDairy ProductsCamembert Pierrot34.0019646.00
4Gai pturageDairy ProductsRaclette Courdavault55.00794,345.00
5Escargots NouveauxSeafoodEscargots de Bourgogne13.2562821.50
6Pasta Buttini s.r.l.Grains/CerealsRavioli Angelo19.5036702.00
7Pasta Buttini s.r.l.Grains/CerealsGnocchi di nonna Alice38.0021798.00
8Ma MaisonMeat/PoultryTourtire7.4521156.45
9Ma MaisonMeat/PoultryPt chinois24.001152,760.00
10G'day, MateGrains/CerealsFilo Mix7.0038266.00
11G'day, MateMeat/PoultryPerth Pasties32.8000.00
12G'day, MateProduceManjimup Dried Apples53.00201,060.00
13Karkki OyBeveragesLakkalikri18.00571,026.00
14Karkki OyConfectionsValkoinen suklaa16.25651,056.25
15Karkki OyConfectionsMaxilaku20.0010200.00
16Zaanse SnoepfabriekConfectionsChocolade12.7515191.25
17Zaanse SnoepfabriekConfectionsZaanse koeken9.5036342.00
18LyngbysildSeafoodRogede sild9.50547.50
19LyngbysildSeafoodSpegesild12.00951,140.00
20Leka TradingBeveragesIpoh Coffee46.0017782.00
21Leka TradingCondimentsGula Malacca19.4527525.15
22Leka TradingGrains/CerealsSingaporean Hokkien Fried Mee14.0026364.00
23New England Seafood CannerySeafoodJack's New England Clam Chowder9.6585820.25
24New England Seafood CannerySeafoodBoston Crab Meat18.401232,263.20
25Aux joyeux ecclsiastiquesBeveragesChartreuse verte18.00691,242.00
26Aux joyeux ecclsiastiquesBeveragesCte de Blaye263.50174,479.50
27Svensk Sjfda ABSeafoodRd Kaviar15.001011,515.00
28Svensk Sjfda ABSeafoodGravad lax26.0011286.00
29Svensk Sjfda ABSeafoodInlagd Sill19.001122,128.00
30Bigfoot BreweriesBeveragesLaughing Lumberjack Lager14.0052728.00
31Bigfoot BreweriesBeveragesSteeleye Stout18.0020360.00
32Bigfoot BreweriesBeveragesSasquatch Ale14.001111,554.00
33Norske MeierierDairy ProductsGeitost2.50112280.00
34Norske MeierierDairy ProductsGudbrandsdalsost36.0026936.00
35Norske MeierierDairy ProductsFlotemysost21.5026559.00
36Formaggi Fortini s.r.l.Dairy ProductsMascarpone Fabioli32.009288.00
37Formaggi Fortini s.r.l.Dairy ProductsGorgonzola Telino12.5000.00
38Formaggi Fortini s.r.l.Dairy ProductsMozzarella di Giovanni34.8014487.20
39Nord-Ost-Fisch Handelsgesellschaft mbHSeafoodNord-Ost Matjeshering25.8910258.90
40Plutzer Lebensmittelgromrkte AGBeveragesRhnbru Klosterbier7.75125968.75
41Plutzer Lebensmittelgromrkte AGCondimentsOriginal Frankfurter grne Soe13.0032416.00
42Plutzer Lebensmittelgromrkte AGGrains/CerealsWimmers gute Semmelkndel33.2522731.50
43Plutzer Lebensmittelgromrkte AGMeat/PoultryThringer Rostbratwurst123.7900.00
44Plutzer Lebensmittelgromrkte AGProduceRssle Sauerkraut45.60261,185.60
45Heli Swaren GmbH & Co. KGConfectionsSchoggi Schokolade43.90492,151.10
46Heli Swaren GmbH & Co. KGConfectionsGumbr Gummibrchen31.2315468.45
47Heli Swaren GmbH & Co. KGConfectionsNuNuCa Nu-Nougat-Creme14.00761,064.00
48Refrescos Americanas LTDABeveragesGuaran Fantstica4.502090.00
49PB Knckebrd ABGrains/CerealsTunnbrd9.0061549.00
50PB Knckebrd ABGrains/CerealsGustaf's Knckebrd21.001042,184.00
51Specialty Biscuits, Ltd.ConfectionsSir Rodney's Scones10.00330.00
52Specialty Biscuits, Ltd.ConfectionsSir Rodney's Marmalade81.00403,240.00
53Specialty Biscuits, Ltd.ConfectionsTeatime Chocolate Biscuits9.2025230.00
54Specialty Biscuits, Ltd.ConfectionsScottish Longbreads12.50675.00
55Pavlova, Ltd.BeveragesOutback Lager15.0015225.00
56Pavlova, Ltd.CondimentsVegie-spread43.90241,053.60
57Pavlova, Ltd.ConfectionsPavlova17.4529506.05
58Pavlova, Ltd.Meat/PoultryAlice Mutton39.0000.00
59Pavlova, Ltd.SeafoodCarnarvon Tigers62.50422,625.00
60Mayumi'sCondimentsGenen Shouyu15.5039604.50
61Mayumi'sProduceTofu23.2535813.75
62Mayumi'sSeafoodKonbu6.0024144.00
63Cooperativa de Quesos 'Las Cabras'Dairy ProductsQueso Cabrales21.0022462.00
64Cooperativa de Quesos 'Las Cabras'Dairy ProductsQueso Manchego La Pastora38.00863,268.00
65Tokyo TradersMeat/PoultryMishi Kobe Niku97.00292,813.00
66Tokyo TradersProduceLonglife Tofu10.00440.00
67Tokyo TradersSeafoodIkura31.0031961.00
68Grandma Kelly's HomesteadCondimentsNorthwoods Cranberry Sauce40.006240.00
69Grandma Kelly's HomesteadCondimentsGrandma's Boysenberry Spread25.001203,000.00
70Grandma Kelly's HomesteadProduceUncle Bob's Organic Dried Pears30.0015450.00
71New Orleans Cajun DelightsCondimentsLouisiana Fiery Hot Pepper Sauce21.05761,599.80
72New Orleans Cajun DelightsCondimentsLouisiana Hot Spiced Okra17.00468.00
73New Orleans Cajun DelightsCondimentsChef Anton's Gumbo Mix21.3500.00
74New Orleans Cajun DelightsCondimentsChef Anton's Cajun Seasoning22.00531,166.00
75Exotic LiquidsBeveragesChang19.0017323.00
76Exotic LiquidsBeveragesChai18.0039702.00
77Exotic LiquidsCondimentsAniseed Syrup10.0013130.00
   Page Summary28.873,11974,050.85
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'showPageSummary' => true,
    'pjax' => true,
    'striped' => false,
    'hover' => true,
    'panel' => ['type' => 'primary', 'heading' => 'Grid Grouping Example'],
    'toggleDataContainer' => ['class' => 'btn-group mr-2 me-2'],
    'columns' => [
        ['class' => 'kartik\grid\SerialColumn'],
        [
            'attribute' => 'supplier_id', 
            'width' => '310px',
            'value' => function ($model, $key, $index, $widget) { 
                return $model->supplier->company_name;
            },
            'filterType' => GridView::FILTER_SELECT2,
            'filter' => ArrayHelper::map(Suppliers::find()->orderBy('company_name')->asArray()->all(), 'id', 'company_name'), 
            'filterWidgetOptions' => [
                'pluginOptions' => ['allowClear' => true],
            ],
            'filterInputOptions' => ['placeholder' => 'Any supplier'],
            'group' => true,  // enable grouping,
            'groupedRow' => true,                    // move grouped column to a single grouped row
            'groupOddCssClass' => 'kv-grouped-row',  // configure odd group cell css class
            'groupEvenCssClass' => 'kv-grouped-row', // configure even group cell css class
            'groupFooter' => function ($model, $key, $index, $widget) { // Closure method
                return [
                    'mergeColumns' => [[0,2]], // columns to merge in summary
                    'content' => [             // content to show in each summary cell
                        0 => 'Summary (' . $model->supplier->company_name . ')',
                        4 => GridView::F_AVG,
                        5 => GridView::F_SUM,
                        6 => GridView::F_SUM,
                    ],
                    'contentFormats' => [      // content reformatting for each summary cell
                        4 => ['format' => 'number', 'decimals' => 2],
                        5 => ['format' => 'number', 'decimals' => 0],
                        6 => ['format' => 'number', 'decimals' => 2],
                    ],
                    'contentOptions' => [      // content html attributes for each summary cell
                        0 => ['style' => 'font-variant:small-caps'],
                        4 => ['style' => 'text-align:right'],
                        5 => ['style' => 'text-align:right'],
                        6 => ['style' => 'text-align:right'],
                    ],
                    // html attributes for group summary row
                    'options' => ['class' => 'info table-info','style' => 'font-weight:bold;']
                ];
            }
        ],
        [
            'attribute' => 'category_id', 
            'width' => '250px',
            'value' => function ($model, $key, $index, $widget) { 
                return $model->category->category_name;
            },
            'filterType' => GridView::FILTER_SELECT2,
            'filter' => ArrayHelper::map(Categories::find()->orderBy('category_name')->asArray()->all(), 'id', 'category_name'), 
            'filterWidgetOptions' => [
                'pluginOptions' => ['allowClear' => true],
            ],
            'filterInputOptions' => ['placeholder' => 'Any category'],
            'group' => true,  // enable grouping
            'subGroupOf' => 1 // supplier column index is the parent group,
            'groupFooter' => function ($model, $key, $index, $widget) { // Closure method
                return [
                    'mergeColumns' => [[2, 3]], // columns to merge in summary
                    'content' => [              // content to show in each summary cell
                        2 => 'Summary (' . $model->category->category_name . ')',
                        4 => GridView::F_AVG,
                        5 => GridView::F_SUM,
                        6 => GridView::F_SUM,
                    ],
                    'contentFormats' => [      // content reformatting for each summary cell
                        4 => ['format' => 'number', 'decimals' => 2],
                        5 => ['format' => 'number', 'decimals' => 0],
                        6 => ['format' => 'number', 'decimals' => 2],
                    ],
                    'contentOptions' => [      // content html attributes for each summary cell
                        4 => ['style' => 'text-align:right'],
                        5 => ['style' => 'text-align:right'],
                        6 => ['style' => 'text-align:right'],
                    ],
                    // html attributes for group summary row
                    'options' => ['class' => 'success table-success','style' => 'font-weight:bold;']
                ];
            },
        ],
        [
            'attribute' => 'product_name',
            'pageSummary' => 'Page Summary',
            'pageSummaryOptions' => ['class' => 'text-right text-end'],
        ],
        [
            'attribute' => 'unit_price',
            'width' => '150px',
            'hAlign' => 'right',
            'format' => ['decimal', 2],
            'pageSummary' => true,
            'pageSummaryFunc' => GridView::F_AVG
        ],
        [
            'attribute' => 'units_in_stock',
            'width' => '150px',
            'hAlign' => 'right',
            'format' => ['decimal', 0],
            'pageSummary' => true
        ],
        [
            'class' => 'kartik\grid\FormulaColumn',
            'header' => 'Amount In Stock',
            'value' => function ($model, $key, $index, $widget) { 
                $p = compact('model', 'key', 'index');
                return $widget->col(4, $p) * $widget->col(5, $p);
            },
            'mergeHeader' => true,
            'width' => '150px',
            'hAlign' => 'right',
            'format' => ['decimal', 2],
            'pageSummary' => true
        ],
    ],
]);

Note

You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.

The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.

 
visitors to Krajee Yii2 Demos since 22-May-2017