我已经安装了kartik网格视图,我从documentation和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插件吗?或者代码缺乏重要的配置??
答案 0 :(得分:3)
试试这个我希望这会帮助你,只需复制并粘贴它,然后单独用你的字段替换字段。
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,
]); ?>
答案 1 :(得分:1)
您只需在网格视图中添加面板标题,或者您应该在该网格视图中的任何位置添加导出按钮
'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
],