Menus

Wednesday, 16 September 2015

YII2 Grid View Advanced Options


INDEX
Karthik Grid View
How to group data in Grid View
Grid View Export Configuration



Karthik Grid View


GridView Demo yii2-grid

GridView yii2-grid Installation and more options


           Karthik Gridview Expand







How to group data in Grid View

Demonstration examples and scenarios for Grouping data using \kartik\grid\GridView





Grid View Export Configuration


Example Grid Code:

$exportFilename = 'custom-filename_' . date("Y-m-d_H-m-s");

        $exportConfig = [

            GridView::HTML  => [
                'label'           => 'HTML',
                'icon'            => 'file-text',
                'iconOptions'     => ['class' => 'text-info'],
                'showHeader'      => TRUE,
                'showPageSummary' => TRUE,
                'showFooter'      => TRUE,
                'showCaption'     => TRUE,
                'filename'        => $exportFilename,
                'alertMsg'        => 'The HTML export file will be generated for download.',
                'options'         => ['title' => 'Hyper Text Markup Language'],
                'mime'            => 'text/html',
                'config'          => [
                    'cssFile' => 'http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css'
                ]
            ],
            GridView::CSV   => [
                'label'           => 'CSV',
                'icon'            => 'file-code-o',
                'iconOptions'     => ['class' => 'text-primary'],
                'showHeader'      => TRUE,
                'showPageSummary' => TRUE,
                'showFooter'      => TRUE,
                'showCaption'     => TRUE,
                'filename'        => $exportFilename,
                'alertMsg'        => 'The CSV export file will be generated for download.',
                'options'         => ['title' => 'Comma Separated Values'],
                'mime'            => 'application/csv',
                'config'          => [
                    'colDelimiter' => ",",
                    'rowDelimiter' => "\r\n",
                ]
            ],
            GridView::EXCEL => [
                'label'           => 'Excel',
                'icon'            => 'file-excel-o',
                'iconOptions'     => ['class' => 'text-success'],
                'showHeader'      => TRUE,
                'showPageSummary' => TRUE,
                'showFooter'      => TRUE,
                'showCaption'     => TRUE,
                'filename'        => $exportFilename,
                'alertMsg'        => 'The EXCEL export file will be generated for download.',
                'options'         => ['title' => 'Microsoft Excel 95+'],
                'mime'            => 'application/vnd.ms-excel',
                'config'          => [
                    'worksheet' => 'Worksheet',
                    'cssFile'   => ''
                ]
            ],
            GridView::PDF   => [
                'label'           => 'PDF',
                'icon'            => 'file-pdf-o',
                'iconOptions'     => ['class' => 'text-danger'],
                'showHeader'      => TRUE,
                'showPageSummary' => TRUE,
                'showFooter'      => TRUE,
                'showCaption'     => TRUE,
                'filename'        => $exportFilename,
                'alertMsg'        => 'The PDF export file will be generated for download.',
                'options'         => ['title' => 'Portable Document Format'],
                'mime'            => 'application/pdf',
                'config'          => [
                    'mode'          => 'c',
                    'format'        => 'A4-L',
                    'destination'   => 'D',
                    'marginTop'     => 20,
                    'marginBottom'  => 20,
                    'cssInline'     => '.kv-wrap{padding:20px;}' .
                        '.kv-align-center{text-align:center;}' .
                        '.kv-align-left{text-align:left;}' .
                        '.kv-align-right{text-align:right;}' .
                        '.kv-align-top{vertical-align:top!important;}' .
                        '.kv-align-bottom{vertical-align:bottom!important;}' .
                        '.kv-align-middle{vertical-align:middle!important;}' .
                        '.kv-page-summary{border-top:4px double #ddd;font-weight: bold;}' .
                        '.kv-table-footer{border-top:4px double #ddd;font-weight: bold;}' .
                        '.kv-table-caption{font-size:1.5em;padding:8px;border:1px solid #ddd;border-bottom:none;}',
                    'methods'       => [
                        'SetHeader' => [
                            ['odd' => $ourPdfHeader, 'even' => $ourPdfHeader]
                        ],
                        'SetFooter' => [
                            ['odd' => $ourPdfFooter, 'even' => $ourPdfFooter]
                        ],
                    ],
                    'options'       => [
                        'title'    => 'Custom Title',
                        'subject'  => 'PDF export',
                        'keywords' => 'pdf'
                    ],
                    'contentBefore' => '',
                    'contentAfter'  => ''
                ]
            ]
        ];



Example and usage


echo GridView::widget([

    'dataProvider' => $dataProvider,
    'formatter' => ['class' => 'yii\i18n\Formatter','nullDisplay' => ''],
    'columns' => $gridColumns,   
    
    'containerOptions' => ['style'=>'overflow: auto',], // only set when $responsive = false
    
    'pjax' => true,
      
    'beforeHeader'=>[
            [
            'columns'=>[
            ['content'=>$content, 'options'=>['colspan'=>count($gridColumns), 'class'=>'text-left warning']],            
            ],
            //'options'=>['class'=>'skip-export'] // remove this row from export
            ]
            ],
    
    
    'bordered' => true,
    'striped' => false,
    'condensed' => false,
    'responsive' => true,
    'hover' => true,
    'floatHeader' => true,
    //'floatHeaderOptions' => ['scrollingTop' => $scrollingTop],
    //'showPageSummary' => true,
    'panel' => [
        'type' => GridView::TYPE_PRIMARY,    
        'before' => 'Date : '.date('d-m-Y'),
        'heading' => '<i class="glyphicon glyphicon-user"></i>&nbsp;<b>UNIVERSITY PAYMENT REPORT</b>',
        //'after' => 'Search Criteria : '.$query,
        //'showFooter' => false,
    ],
    
    
    'exportConfig' => [
                 GridView::CSV   => [
                'label'           => 'CSV',
                'icon'            => 'file-code-o',
                'iconOptions'     => ['class' => 'text-primary'],
                'showHeader'      => FALSE,
                'showPageSummary' => TRUE,
                'showFooter'      => TRUE,
                'showCaption'     => TRUE,
                'filename'        => $exportFilename,
                'alertMsg'        => 'The CSV export file will be generated for download.',
                'options'         => ['title' => 'Comma Separated Values'],
                'mime'            => 'application/csv',
                'config'          => [
                    'colDelimiter' => ",",
                    'rowDelimiter' => "\r\n",
                ]
            ],
            GridView::EXCEL => [
                'label'           => 'Excel',
                'icon'            => 'file-excel-o',
                'iconOptions'     => ['class' => 'text-success'],
                'showHeader'      => TRUE,
                'showPageSummary' => TRUE,
                'showFooter'      => TRUE,
                'showCaption'     => TRUE,
                'filename'        => $exportFilename,
                'alertMsg'        => 'The EXCEL export file will be generated for download.',
                'options'         => ['title' => 'Microsoft Excel 95+'],
                'mime'            => 'application/vnd.ms-excel',
                'config'          => [
                    'worksheet' => 'Worksheet',
                    'cssFile'   => ''
                ]
            ],
            ],

   
      
     // set your toolbar
    'toolbar'=> [
        ['content'=>
            Html::a('<i class="glyphicon glyphicon-plus"></i>',['universitypayment/index'], ['title'=>'Add New Criteria', 'class'=>'btn btn-success']), 
            
        ],
        '{export}',
        //'{toggleData}',
    ],
        
]);




Some examples of grid export
http://demos.krajee.com/grid#grid-export





No comments:

Post a Comment