Krajee

Group Grid Demo #3

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

Variation of example # 2, that shows grouping of parent column data as a separate grouped header row.



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)

Showing 1-20 of 77 items.
Grid Grouping Example 3
#SupplierCategoryProduct NameUnit PriceUnits In StockAmount In Stock
 
 
1Exotic LiquidsBeveragesChang19.0017323.00
2Exotic LiquidsBeveragesChai18.0039702.00
3Exotic LiquidsCondimentsAniseed Syrup10.0013130.00
4New Orleans Cajun DelightsCondimentsChef Anton's Cajun Seasoning22.00531,166.00
5New Orleans Cajun DelightsCondimentsChef Anton's Gumbo Mix21.3500.00
6New Orleans Cajun DelightsCondimentsLouisiana Fiery Hot Pepper Sauce21.05761,599.80
7New Orleans Cajun DelightsCondimentsLouisiana Hot Spiced Okra17.00468.00
8Grandma Kelly's HomesteadCondimentsGrandma's Boysenberry Spread25.001203,000.00
9Grandma Kelly's HomesteadCondimentsNorthwoods Cranberry Sauce40.006240.00
10Grandma Kelly's HomesteadProduceUncle Bob's Organic Dried Pears30.0015450.00
11Tokyo TradersMeat/PoultryMishi Kobe Niku97.00292,813.00
12Tokyo TradersProduceLonglife Tofu10.00440.00
13Tokyo TradersSeafoodIkura31.0031961.00
14Cooperativa de Quesos 'Las Cabras'Dairy ProductsQueso Cabrales21.0022462.00
15Cooperativa de Quesos 'Las Cabras'Dairy ProductsQueso Manchego La Pastora38.00863,268.00
16Mayumi'sCondimentsGenen Shouyu15.5039604.50
17Mayumi'sProduceTofu23.2535813.75
18Mayumi'sSeafoodKonbu6.0024144.00
19Pavlova, Ltd.BeveragesOutback Lager15.0015225.00
20Pavlova, Ltd.CondimentsVegie-spread43.90241,053.60
   Page Summary26.2065218,063.65
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'showPageSummary' => true,
    'pjax' => true,
    'striped' => true,
    '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
        ],
        [
            '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
        ],
        [
            '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