Krajee

Group Grid Demo #1

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

Example showing the grouping of grid data for a single column that is pre-sorted. Note that the extension can group columns, irrespective of the position of the column in the grid (second column in this example). This example also demonstrates grouping on a related field from another table. It also includes an advanced scenario of using \kartik\grid\FormulaColumn to calculate the Amount value.



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 61-77 of 77 items.
Grid Grouping Example 1
#SupplierCategoryProduct NameUnit PriceUnits In StockAmount In Stock
 
 
61Zaanse SnoepfabriekConfectionsChocolade12.7515191.25
62Zaanse SnoepfabriekConfectionsZaanse koeken9.5036342.00
63Karkki OyBeveragesLakkalikri18.00571,026.00
64Karkki OyConfectionsValkoinen suklaa16.25651,056.25
65Karkki OyConfectionsMaxilaku20.0010200.00
66G'day, MateGrains/CerealsFilo Mix7.0038266.00
67G'day, MateMeat/PoultryPerth Pasties32.8000.00
68G'day, MateProduceManjimup Dried Apples53.00201,060.00
69Ma MaisonMeat/PoultryPt chinois24.001152,760.00
70Ma MaisonMeat/PoultryTourtire7.4521156.45
71Pasta Buttini s.r.l.Grains/CerealsRavioli Angelo19.5036702.00
72Pasta Buttini s.r.l.Grains/CerealsGnocchi di nonna Alice38.0021798.00
73Escargots NouveauxSeafoodEscargots de Bourgogne13.2562821.50
74Gai pturageDairy ProductsCamembert Pierrot34.0019646.00
75Gai pturageDairy ProductsRaclette Courdavault55.00794,345.00
76Forts d'rablesCondimentsSirop d'rable28.501133,220.50
77Forts d'rablesConfectionsTarte au sucre49.3017838.10
   Page Summary25.7872418,429.05
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']
        ],
        [
            '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