Krajee

Menu with Grid View (Advanced 2)

Thankful to Krajee! BUY A COFFEEor to get more out of us.
Variation of advanced case 1. Display export menu dropdown merged along with the dropdown items of the default kartik\grid\GridView export menu. Uses the plugin ability of kartik\grid\GridView. Display your own customized menu list and style it with CSS. Note you will set asDropdown to false in this case. Hence the Columns Selector will not be displayed (you will need to render the exportColumnsView on your own if needed).

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 6-10 of 20 items.
Library
#IDNameAuthorColorPublish DateStatusBuy Amount ($)Sell Amount ($)Actions
61006Catch-22Joseph Hellercyan2011-08-21Active85.00105.50
71007The Catcher in the RyeJ. D. Salingerred2006-10-17Active105.00125.50
81008BelovedToni Morrisongreen2000-10-01Inactive130.00154.99
91009The Sound and the FuryWilliam Faulknerbrown2005-07-18Active106.00125.50
101010To Kill a Mockingbird Harper Leeorange2013-06-19Inactive79.0098.50
use kartik\export\ExportMenu;
use kartik\grid\GridView;
use kartik\helpers\Html;
$customDropdown = [
    'options' => ['tag' => false], 
    'linkOptions' => ['class' => 'dropdown-item']
];
$fullExportMenu = ExportMenu::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'target' => ExportMenu::TARGET_BLANK,
    'asDropdown' => false, // this is important for this case so we just need to get a HTML list    
    'dropdownOptions' => [
        'label' => '<i class="fas fa-external-link-alt"></i> Full'
    ],
    'exportConfig' => [ // set styling for your custom dropdown list items
        ExportMenu::FORMAT_CSV => $customDropdown,
        ExportMenu::FORMAT_TEXT => $customDropdown,
        ExportMenu::FORMAT_HTML => $customDropdown,
        ExportMenu::FORMAT_PDF => $customDropdown,
        ExportMenu::FORMAT_EXCEL => $customDropdown,
        ExportMenu::FORMAT_EXCEL_X => $customDropdown,
    ],
]);
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'panel' => [
        'type' => GridView::TYPE_PRIMARY,
        'heading' => '<h3 class="panel-title"><i class="fas fa-book"></i> Library</h3>',
    ],
    'exportContainer' => [
        'class' => 'btn-group mr-2 me-2'
    ],
    // the toolbar setting is default
    'toolbar' => [
        '{export}',
        ['content'=>
            Html::button('<i class="fas fa-plus"></i>', ['type'=>'button', 'title'=>Yii::t('kvgrid', 'Add Book'), 'class'=>'btn btn-success', 'onclick'=>'alert("This will launch the book creation form.\n\nDisabled for this demo!");']) . ' '.
                Html::a('<i class="fas fa-redo"></i>', ['grid-demo'], ['data-pjax'=>0, 'class' => 'btn btn-outline-secondary btn-default', 'title'=>Yii::t('kvgrid', 'Reset Grid')])
        ],
    ],
    // configure your GRID inbuilt export dropdown to include additional items
    'export' => [
        'itemsAfter'=> [
            '<div role="presentation" class="dropdown-divider"></div>',
            '<div class="dropdown-header">Export All Data</div>',
            $fullExportMenu
        ]
    ],
]);
$gridColumns = [
    ['class' => 'kartik\grid\SerialColumn'],
    'id',
    'name',
    [
        'attribute'=>'author_id',
        'label'=>'Author',
        'vAlign'=>'middle',
        'width'=>'190px',
        'value'=>function ($model, $key, $index, $widget) { 
            return Html::a($model->author->name, '#', []);
        },
        'format'=>'raw'
    ],
    'color',
    'publish_date',
    'status',
    ['attribute'=>'buy_amount','format'=>['decimal',2], 'hAlign'=>'right', 'width'=>'110px'],
    ['attribute'=>'sell_amount','format'=>['decimal',2], 'hAlign'=>'right', 'width'=>'110px'],
    ['class' => 'kartik\grid\ActionColumn', 'urlCreator'=>function(){return '#';}]
];

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