kartik\grid\GridView 合计,多选,导出excel,header修改 等方法集合!

先上完整demo

具体的以后再说

<?php

//use yii\web\View;
use kartik\grid\GridView;
use yii\bootstrap\Html;
use backend\helps\ArrayHelper;
use yii\helpers\Url;
use kartik\grid\SerialColumn;
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax'=>true, // 使用pjax
'striped' => false,
'hover' => true,
'showPageSummary' => true,
'panel' => [
'heading'=>false,//不要了
'before'=>'<div style="margin-top:8px">{summary}</div>',//放在before中,前面的div主要是想让它好看
],
'toolbar'=> [
['content'=>
Html::a('批量下一步', "javascript:void(0)", ['data-pjax'=>0, 'class'=>'btn btn-success selectColumn', 'title'=>"批量下一步"]).
Html::a('<i class="glyphicon glyphicon-repeat"></i>', "javascript:layer.load(1);location.reload();", ['data-pjax'=>0, 'class'=>'btn btn-default', 'title'=>"重置"])
],
'{export}',
'{toggleData}',
],
'exportConfig'=>[
GridView::EXCEL=>[
'filename' => "excel",
'showPageSummary' => true,
],
], 'columns' => [
['class' => 'kartik\grid\SerialColumn'],
['class' => 'kartik\grid\CheckboxColumn'], //需要配合自定义的gridview /**
[
'class' => '\kartik\grid\FormulaColumn',
"label" =>"共收费",
"format"=>"text",
'value' => function ($model, $key, $index, $widget) {
// $p = compact('model', 'key', 'index');
//在下面写下你的公式
return $model->price + $model->exprice;
},
'pageSummary' => true
], */
'patent_id',
'company', [
"label" => "处理部门",
'attribute' => 'department_id',
'value' => function ($data) {
$arr = ArrayHelper::get_correspond_list('get_department_list', 'id', 'name');
return @$arr[$data["patent"]->department_id];
},
'filter' => ArrayHelper::get_correspond_list('get_department_list', 'id', 'name')
], [
'attribute' => 'price',
'format' => 'text',
'value' => function ($data) {
return $data->price;
},
'pageSummary' => true //需要合计 添加该值
],
[
'attribute' => 'status',
'format' => 'html',
'value' => function ($data) {
ArrayHelper::get_patent_child_status();
return ArrayHelper::dropDown('get_patent_child_status_label', $data->status); // 如果是数组数据则为 $data['name'] ,例如,使用 SqlDataProvider 的情形。
},
'filter' => ArrayHelper::dropDown('get_patent_child_status')
],
[
'attribute' => 'edit_time',
'value' => function ($data) {
return ArrayHelper::get_date_time($data->edit_time);
},
],
[
'class' => 'kartik\grid\ActionColumn',//必须
"header" => "操作",
'template' => '{update} {delete}',
"buttons" => [ "update" => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', Url::to(['patentpay/update', 'id' => $model->id]), ['title' => '修改', 'class' => 'ahref']);
},
"delete" => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', Url::to(['patentpay/delete', 'id' => $model->id]), ['title' => '删除', 'class' => 'actionDoing']);
},
], ], ]
]); ?>
上一篇:关于Java的特点之多态


下一篇:hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)