Krajee

Group Grid Demo #2

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

An example extending example # 1 with grouping by multiple columns (second and third columns) that are sorted. The third column has been setup as a sub group of second column (thereby rendering a nested grouping). Note that subGroupOf property is necessary within the child column for this to be meaningful and effective.



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 21-40 of 77 items.
Grid Grouping Example 2
#SupplierCategoryProduct NameUnit PriceUnits In StockAmount In Stock
 
 
21Pavlova, Ltd.ConfectionsPavlova17.4529506.05
22Pavlova, Ltd.Meat/PoultryAlice Mutton39.0000.00
23Pavlova, Ltd.SeafoodCarnarvon Tigers62.50422,625.00
24Specialty Biscuits, Ltd.ConfectionsScottish Longbreads12.50675.00
25Specialty Biscuits, Ltd.ConfectionsTeatime Chocolate Biscuits9.2025230.00
26Specialty Biscuits, Ltd.ConfectionsSir Rodney's Marmalade81.00403,240.00
27Specialty Biscuits, Ltd.ConfectionsSir Rodney's Scones10.00330.00
28PB Knckebrd ABGrains/CerealsGustaf's Knckebrd21.001042,184.00
29PB Knckebrd ABGrains/CerealsTunnbrd9.0061549.00
30Refrescos Americanas LTDABeveragesGuaran Fantstica4.502090.00
31Heli Swaren GmbH & Co. KGConfectionsNuNuCa Nu-Nougat-Creme14.00761,064.00
32Heli Swaren GmbH & Co. KGConfectionsGumbr Gummibrchen31.2315468.45
33Heli Swaren GmbH & Co. KGConfectionsSchoggi Schokolade43.90492,151.10
34Plutzer Lebensmittelgromrkte AGBeveragesRhnbru Klosterbier7.75125968.75
35Plutzer Lebensmittelgromrkte AGCondimentsOriginal Frankfurter grne Soe13.0032416.00
36Plutzer Lebensmittelgromrkte AGGrains/CerealsWimmers gute Semmelkndel33.2522731.50
37Plutzer Lebensmittelgromrkte AGMeat/PoultryThringer Rostbratwurst123.7900.00
38Plutzer Lebensmittelgromrkte AGProduceRssle Sauerkraut45.60261,185.60
39Nord-Ost-Fisch Handelsgesellschaft mbHSeafoodNord-Ost Matjeshering25.8910258.90
40Formaggi Fortini s.r.l.Dairy ProductsMascarpone Fabioli32.009288.00
   Page Summary31.8369417,061.35
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
        ],
        [
            '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