kartik gridview 上的 YII2 导出菜单未显示

YII2 export menu on kartik gridview not showing

我已经安装了 kartik gridview 并且从 documentation and demo,我复制了一些代码并得到了这个..

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'hover'=>true,
        'condensed'=>true,
        'floatHeader'=>true,
        'bordered'=>true,
        'pjax' => true,
        'toolbar'=>[
                    '{export}',
                    '{toggleData}',
                    ],
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            [
                'attribute'=>'province',
                'label'=>'Province',
                'value'=>'cityCode.provCode.prov_name',
            ],....

该页面可以很好地显示 gridview,但缺少导出按钮。我还需要下载 export 插件吗?还是代码缺少重要配置??

您只需在网格视图中添加面板标题,或者您应该在该网格视图中任何您想要的地方添加导出按钮

'panel' => [
    'heading'=>'<h3 class="panel-title"><i class="glyphicon glyphicon-globe"></i> '. Html::encode($this->title).'</h3>',
    'type'=>'primary',
    'before'=>Html::a('<i class="glyphicon glyphicon-plus"></i>New Registration', ['create'], ['class' => 'btn btn-primary']),
    'showFooter'=>false
],

试试这个,希望对您有所帮助,只需复制并粘贴它,然后单独用您的字段替换字段就可以了。

use kartik\export\ExportMenu;

<?php $gridColumns = [
    ['class' => 'yii\grid\SerialColumn'],
        'companyname',
        'companyaddress:ntext',
        'hrname',
        'email:email',
        'mobile',
        'typeofcompany',
        'companytype',
        'relationoption',
        'relation',
    ['class' => 'yii\grid\ActionColumn'],
    ]; ?>

<?= ExportMenu::widget([
        'dataProvider' => $dataProvider,
        'columns' => $gridColumns,
        'columnSelectorOptions'=>[
            'label' => 'Columns',
            'class' => 'btn btn-danger'
        ],
        'fontAwesome' => true,
        'dropdownOptions' => [
            'label' => 'Export All',
            'class' => 'btn btn-success'
        ]
    ]); ?>

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => $gridColumns,
]); ?>