From de3877eddfa14b9947c72eb4bcc553f45a05d853 Mon Sep 17 00:00:00 2001 From: iron Date: Tue, 12 Nov 2019 14:22:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E5=86=99=E5=92=8C=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/models/Category.php | 61 +- common/models/CategorySearch.php | 42 +- composer.json | 3 +- composer.lock | 356 +++++++- kcadmin/controllers/CategoryController.php | 70 +- kcadmin/views/category/index.php | 43 +- vendor/blobt/grid/GridView.php | 134 ++- vendor/iron/grid/ActionColumn.php | 246 ++++++ vendor/iron/widget/Excel.php | 958 +++++++++++++++++++++ 9 files changed, 1792 insertions(+), 121 deletions(-) create mode 100644 vendor/iron/grid/ActionColumn.php create mode 100755 vendor/iron/widget/Excel.php diff --git a/common/models/Category.php b/common/models/Category.php index 3dcc1e2..d9d6ddb 100644 --- a/common/models/Category.php +++ b/common/models/Category.php @@ -17,7 +17,8 @@ use yii\behaviors\TimestampBehavior; * @property int $created_at * @property int $updated_at */ -class Category extends \yii\db\ActiveRecord { +class Category extends \yii\db\ActiveRecord +{ const ICON_TYPE_BOOSTARAP = 1; const ICON_TYPE_AWESOME = 2; @@ -30,16 +31,18 @@ class Category extends \yii\db\ActiveRecord { /** * {@inheritdoc} */ - public static function tableName() { + public static function tableName() + { return 'category'; } /** * {@inheritdoc} */ - public function rules() { + public function rules() + { return [ - [['icon_type','cat_name','created_at'], 'required'], + [['icon_type', 'cat_name', 'created_at'], 'required'], [['icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], [['description'], 'string'], [['cat_name', 'icon'], 'string', 'max' => 64], @@ -49,7 +52,8 @@ class Category extends \yii\db\ActiveRecord { /** * {@inheritdoc} */ - public function attributeLabels() { + public function attributeLabels() + { return [ 'id' => 'ID', 'cat_name' => '类名', @@ -62,7 +66,52 @@ class Category extends \yii\db\ActiveRecord { ]; } - public function behaviors() { + public static function columns() + { + return [ + [ + 'class' => 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + [ + 'attribute' => 'id', + 'width' => '5%', + 'align' => 'center' + ], + [ + 'attribute' => 'created_at', + 'width' => '7%', + 'format' => 'date' + ], + [ + 'attribute' => 'cat_name', + 'width' => '13%', + ], + [ + 'attribute' => 'icon', + 'width' => '5%', + ], + [ + 'attribute' => 'icon_type', + 'width' => '7%', + 'showConstText' => true + ], + [ + 'attribute' => 'description', + 'enableSorting' => false, + 'format' => 'ntext', + 'width' => '50%', + ], + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + ], + ]; + } + + public function behaviors() + { return [ TimestampBehavior::className() ]; diff --git a/common/models/CategorySearch.php b/common/models/CategorySearch.php index 706f346..63aab51 100644 --- a/common/models/CategorySearch.php +++ b/common/models/CategorySearch.php @@ -2,24 +2,27 @@ namespace common\models; +use common\models\Category; use yii\base\Model; use yii\data\ActiveDataProvider; -use common\models\Category; use yii\helpers\ArrayHelper; /** * CategorySearch represents the model behind the search form of `\common\models\Category`. */ -class CategorySearch extends Category { +class CategorySearch extends Category +{ - public function attributes() { + public function attributes() + { return ArrayHelper::merge(['created_at_range'], parent::attributes()); } /** * {@inheritdoc} */ - public function rules() { + public function rules() + { return [ [['id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], [['cat_name', 'icon', 'description', 'created_at_range'], 'safe'], @@ -29,11 +32,25 @@ class CategorySearch extends Category { /** * {@inheritdoc} */ - public function scenarios() { + public function scenarios() + { // bypass scenarios() implementation in the parent class return Model::scenarios(); } + public function allData($params) + { + + $query = Category::find(); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => false, + 'sort' => false + ]); + $this->load($params); + return $this->filter($query, $dataProvider); + } + /** * Creates data provider instance with search query applied * @@ -41,7 +58,8 @@ class CategorySearch extends Category { * * @return ActiveDataProvider */ - public function search($params) { + public function search($params) + { $query = Category::find(); // add conditions that should always apply here @@ -57,8 +75,12 @@ class CategorySearch extends Category { ] ], ]); - $this->load($params); + return $this->filter($query, $dataProvider); + } + + private function filter($query, $dataProvider) + { if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails @@ -66,7 +88,7 @@ class CategorySearch extends Category { return $dataProvider; } - // grid filtering conditions +// grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'icon_type' => $this->icon_type, @@ -76,8 +98,8 @@ class CategorySearch extends Category { ]); $query->andFilterWhere(['like', 'cat_name', $this->cat_name]) - ->andFilterWhere(['like', 'icon', $this->icon]) - ->andFilterWhere(['like', 'description', $this->description]); + ->andFilterWhere(['like', 'icon', $this->icon]) + ->andFilterWhere(['like', 'description', $this->description]); if ($this->created_at_range) { $arr = explode(' ~ ', $this->created_at_range); diff --git a/composer.json b/composer.json index 768fceb..3719903 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "require": { "php": ">=7.1.0", "yiisoft/yii2": "~2.0.14", - "yiisoft/yii2-bootstrap": "^2.0@dev" + "yiisoft/yii2-bootstrap": "^2.0@dev", + "moonlandsoft/yii2-phpexcel": "*" }, "repositories": { "asset_packagist": { diff --git a/composer.lock b/composer.lock index c59a1f7..d760883 100644 --- a/composer.lock +++ b/composer.lock @@ -4,14 +4,14 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f3ddaead9bc7b0924e8f9ccf68c842ff", + "content-hash": "3f23bd556b4acf6c2728200635bf4eb6", "packages": [ { "name": "bower-asset/bootstrap", "version": "v3.4.1", "source": { "type": "git", - "url": "https://github.com/twbs/bootstrap.git", + "url": "git@github.com:twbs/bootstrap.git", "reference": "68b0d231a13201eb14acd3dc84e51543d16e5f7e" }, "dist": { @@ -153,7 +153,7 @@ "version": "v1.3.2", "source": { "type": "git", - "url": "https://github.com/bestiejs/punycode.js.git", + "url": "git@github.com:bestiejs/punycode.js.git", "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3" }, "dist": { @@ -322,6 +322,356 @@ ], "time": "2018-02-23T01:58:20+00:00" }, + { + "name": "markbaker/complex", + "version": "1.4.7", + "source": { + "type": "git", + "url": "https://github.com/MarkBaker/PHPComplex.git", + "reference": "1ea674a8308baf547cbcbd30c5fcd6d301b7c000" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/1ea674a8308baf547cbcbd30c5fcd6d301b7c000", + "reference": "1ea674a8308baf547cbcbd30c5fcd6d301b7c000", + "shasum": "" + }, + "require": { + "php": "^5.6.0|^7.0.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3", + "phpcompatibility/php-compatibility": "^8.0", + "phpdocumentor/phpdocumentor": "2.*", + "phploc/phploc": "2.*", + "phpmd/phpmd": "2.*", + "phpunit/phpunit": "^4.8.35|^5.4.0", + "sebastian/phpcpd": "2.*", + "squizlabs/php_codesniffer": "^3.3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Complex\\": "classes/src/" + }, + "files": [ + "classes/src/functions/abs.php", + "classes/src/functions/acos.php", + "classes/src/functions/acosh.php", + "classes/src/functions/acot.php", + "classes/src/functions/acoth.php", + "classes/src/functions/acsc.php", + "classes/src/functions/acsch.php", + "classes/src/functions/argument.php", + "classes/src/functions/asec.php", + "classes/src/functions/asech.php", + "classes/src/functions/asin.php", + "classes/src/functions/asinh.php", + "classes/src/functions/atan.php", + "classes/src/functions/atanh.php", + "classes/src/functions/conjugate.php", + "classes/src/functions/cos.php", + "classes/src/functions/cosh.php", + "classes/src/functions/cot.php", + "classes/src/functions/coth.php", + "classes/src/functions/csc.php", + "classes/src/functions/csch.php", + "classes/src/functions/exp.php", + "classes/src/functions/inverse.php", + "classes/src/functions/ln.php", + "classes/src/functions/log2.php", + "classes/src/functions/log10.php", + "classes/src/functions/negative.php", + "classes/src/functions/pow.php", + "classes/src/functions/rho.php", + "classes/src/functions/sec.php", + "classes/src/functions/sech.php", + "classes/src/functions/sin.php", + "classes/src/functions/sinh.php", + "classes/src/functions/sqrt.php", + "classes/src/functions/tan.php", + "classes/src/functions/tanh.php", + "classes/src/functions/theta.php", + "classes/src/operations/add.php", + "classes/src/operations/subtract.php", + "classes/src/operations/multiply.php", + "classes/src/operations/divideby.php", + "classes/src/operations/divideinto.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Baker", + "email": "mark@lange.demon.co.uk" + } + ], + "description": "PHP Class for working with complex numbers", + "homepage": "https://github.com/MarkBaker/PHPComplex", + "keywords": [ + "complex", + "mathematics" + ], + "time": "2018-10-13T23:28:42+00:00" + }, + { + "name": "markbaker/matrix", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/MarkBaker/PHPMatrix.git", + "reference": "5348c5a67e3b75cd209d70103f916a93b1f1ed21" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/5348c5a67e3b75cd209d70103f916a93b1f1ed21", + "reference": "5348c5a67e3b75cd209d70103f916a93b1f1ed21", + "shasum": "" + }, + "require": { + "php": "^5.6.0|^7.0.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "dev-master", + "phpcompatibility/php-compatibility": "dev-master", + "phploc/phploc": "^4", + "phpmd/phpmd": "dev-master", + "phpunit/phpunit": "^5.7", + "sebastian/phpcpd": "^3.0", + "squizlabs/php_codesniffer": "^3.0@dev" + }, + "type": "library", + "autoload": { + "psr-4": { + "Matrix\\": "classes/src/" + }, + "files": [ + "classes/src/functions/adjoint.php", + "classes/src/functions/antidiagonal.php", + "classes/src/functions/cofactors.php", + "classes/src/functions/determinant.php", + "classes/src/functions/diagonal.php", + "classes/src/functions/identity.php", + "classes/src/functions/inverse.php", + "classes/src/functions/minors.php", + "classes/src/functions/trace.php", + "classes/src/functions/transpose.php", + "classes/src/operations/add.php", + "classes/src/operations/directsum.php", + "classes/src/operations/subtract.php", + "classes/src/operations/multiply.php", + "classes/src/operations/divideby.php", + "classes/src/operations/divideinto.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Baker", + "email": "mark@lange.demon.co.uk" + } + ], + "description": "PHP Class for working with matrices", + "homepage": "https://github.com/MarkBaker/PHPMatrix", + "keywords": [ + "mathematics", + "matrix", + "vector" + ], + "time": "2019-10-06T11:29:25+00:00" + }, + { + "name": "moonlandsoft/yii2-phpexcel", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/moonlandsoft/yii2-phpexcel.git", + "reference": "ccf28ff8ce2c665a7769dd6516098b4a35c8c309" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/moonlandsoft/yii2-phpexcel/zipball/ccf28ff8ce2c665a7769dd6516098b4a35c8c309", + "reference": "ccf28ff8ce2c665a7769dd6516098b4a35c8c309", + "shasum": "" + }, + "require": { + "phpoffice/phpspreadsheet": "*", + "yiisoft/yii2": "*" + }, + "type": "yii2-extension", + "autoload": { + "psr-4": { + "moonland\\phpexcel\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Moh Khoirul Anam", + "email": "moh.khoirul.anaam@gmail.com" + } + ], + "description": "Exporting PHP to Excel or Importing Excel to PHP", + "keywords": [ + "excel", + "export", + "extension", + "import", + "xls", + "yii2" + ], + "time": "2019-01-31T14:14:03+00:00" + }, + { + "name": "phpoffice/phpspreadsheet", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/PHPOffice/PhpSpreadsheet.git", + "reference": "13eaeb39cfaed16409f7fd9d1968e08be7bfd7e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/13eaeb39cfaed16409f7fd9d1968e08be7bfd7e5", + "reference": "13eaeb39cfaed16409f7fd9d1968e08be7bfd7e5", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-dom": "*", + "ext-fileinfo": "*", + "ext-gd": "*", + "ext-iconv": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-simplexml": "*", + "ext-xml": "*", + "ext-xmlreader": "*", + "ext-xmlwriter": "*", + "ext-zip": "*", + "ext-zlib": "*", + "markbaker/complex": "^1.4", + "markbaker/matrix": "^1.1", + "php": "^7.1", + "psr/simple-cache": "^1.0" + }, + "require-dev": { + "dompdf/dompdf": "^0.8.0", + "friendsofphp/php-cs-fixer": "@stable", + "jpgraph/jpgraph": "^4.0", + "mpdf/mpdf": "^7.0.0", + "phpcompatibility/php-compatibility": "^8.0", + "phpunit/phpunit": "^7.5", + "squizlabs/php_codesniffer": "^3.3", + "tecnickcom/tcpdf": "^6.2" + }, + "suggest": { + "dompdf/dompdf": "Option for rendering PDF with PDF Writer", + "jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers", + "mpdf/mpdf": "Option for rendering PDF with PDF Writer", + "tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-or-later" + ], + "authors": [ + { + "name": "Maarten Balliauw", + "homepage": "https://blog.maartenballiauw.be" + }, + { + "name": "Mark Baker", + "homepage": "https://markbakeruk.net" + }, + { + "name": "Franck Lefevre", + "homepage": "https://rootslabs.net" + }, + { + "name": "Erik Tilt" + }, + { + "name": "Adrien Crivelli" + } + ], + "description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine", + "homepage": "https://github.com/PHPOffice/PhpSpreadsheet", + "keywords": [ + "OpenXML", + "excel", + "gnumeric", + "ods", + "php", + "spreadsheet", + "xls", + "xlsx" + ], + "time": "2019-10-31T23:52:20+00:00" + }, + { + "name": "psr/simple-cache", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "time": "2017-10-23T01:57:42+00:00" + }, { "name": "yiisoft/yii2", "version": "dev-master", diff --git a/kcadmin/controllers/CategoryController.php b/kcadmin/controllers/CategoryController.php index c6cf654..5dea5bc 100644 --- a/kcadmin/controllers/CategoryController.php +++ b/kcadmin/controllers/CategoryController.php @@ -2,9 +2,11 @@ namespace kcadmin\controllers; +use common\models\Cat; use Yii; use common\models\Category; use common\models\CategorySearch; +use yii\helpers\Html; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -12,12 +14,15 @@ use yii\filters\VerbFilter; /** * CategoryController implements the CRUD actions for Category model. */ -class CategoryController extends Controller { +class CategoryController extends Controller +{ public $enableCsrfValidation = false; + /** * {@inheritdoc} */ - public function behaviors() { + public function behaviors() + { return [ 'verbs' => [ 'class' => VerbFilter::className(), @@ -28,24 +33,45 @@ class CategoryController extends Controller { ]; } - public function actions() { + public function actions() + { return [ - 'test'=>[ - 'class'=>'iron\actions\UploadAction', + 'test' => [ + 'class' => 'iron\actions\UploadAction', ] ]; } + + public function actionExport() + { + $searchModel = new CategorySearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' => "category" . "-" . date('Y-m-d H/i/s', time()), + 'columns' => Category::columns() + ]); + } + /** * Lists all Category models. * @return mixed */ - public function actionIndex() { + public function actionIndex() + { $searchModel = new CategorySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => Category::columns() ]); } @@ -55,9 +81,10 @@ class CategoryController extends Controller { * @return mixed * @throws NotFoundHttpException if the model cannot be found */ - public function actionView($id) { + public function actionView($id) + { return $this->render('view', [ - 'model' => $this->findModel($id), + 'model' => $this->findModel($id), ]); } @@ -66,7 +93,8 @@ class CategoryController extends Controller { * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ - public function actionCreate() { + public function actionCreate() + { $model = new Category(); if ($model->load(Yii::$app->request->post()) && $model->save()) { @@ -74,7 +102,7 @@ class CategoryController extends Controller { } return $this->render('create', [ - 'model' => $model, + 'model' => $model, ]); } @@ -85,7 +113,8 @@ class CategoryController extends Controller { * @return mixed * @throws NotFoundHttpException if the model cannot be found */ - public function actionUpdate($id) { + public function actionUpdate($id) + { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { @@ -93,7 +122,7 @@ class CategoryController extends Controller { } return $this->render('update', [ - 'model' => $model, + 'model' => $model, ]); } @@ -104,16 +133,18 @@ class CategoryController extends Controller { * @return mixed * @throws NotFoundHttpException if the model cannot be found */ - public function actionDelete($id) { + public function actionDelete($id) + { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** - * + * */ - public function actionDeletes() { + public function actionDeletes() + { //获取前端post的记录id $ids = Yii::$app->request->post('ids'); } @@ -125,7 +156,8 @@ class CategoryController extends Controller { * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ - protected function findModel($id) { + protected function findModel($id) + { if (($model = Category::findOne($id)) !== null) { return $model; } diff --git a/kcadmin/views/category/index.php b/kcadmin/views/category/index.php index bab362a..02af451 100644 --- a/kcadmin/views/category/index.php +++ b/kcadmin/views/category/index.php @@ -11,9 +11,11 @@ use blobt\grid\GridView; $this->title = 'Categories'; $this->params['breadcrumbs'][] = $this->title; + ?>
+ 'btn btn-default'])?> $dataProvider, 'filter' => $this->render("_search", ['model' => $searchModel]), @@ -27,46 +29,7 @@ $this->params['breadcrumbs'][] = $this->title; "url" => "/category/others" ], ], - 'columns' => [ - [ - 'class' => 'blobt\grid\CheckboxColumn', - 'width' => '2%', - 'align' => 'center' - ], - [ - 'attribute' => 'id', - 'width' => '5%', - 'align' => 'center' - ], - [ - 'attribute' => 'created_at', - 'width' => '7%', - 'format' => 'date' - ], - [ - 'attribute' => 'cat_name', - 'width' => '13%', - ], - [ - 'attribute' => 'icon', - 'width' => '5%', - ], - [ - 'attribute' => 'icon_type', - 'width' => '7%', - 'showConstText' => true - ], - [ - 'attribute' => 'description', - 'enableSorting' => false, - 'format' => 'ntext', - 'width' => '50%', - ], - [ - 'class' => 'blobt\grid\ActionColumn', - 'align' => 'center', - ], - ], + 'columns' => $columns ]); ?>
diff --git a/vendor/blobt/grid/GridView.php b/vendor/blobt/grid/GridView.php index bd3ebc4..ff0a507 100644 --- a/vendor/blobt/grid/GridView.php +++ b/vendor/blobt/grid/GridView.php @@ -43,7 +43,8 @@ use blobt\web\GridViewAsset; * @email 380255922@qq.com * @created Aug 13, 2019 */ -class GridView extends BaseListView { +class GridView extends BaseListView +{ /** * @var string 渲染列数据的类,默认是'yii\grid\DataColumn' @@ -66,12 +67,12 @@ class GridView extends BaseListView { public $tableOptions = ['class' => 'table table-bordered table-hover dataTable']; /** - * @var array 表格头部html属性 + * @var array 表格头部html属性 */ public $headerRowOptions = []; /** - * @var array 表格脚部html属性 + * @var array 表格脚部html属性 */ public $footerRowOptions = []; @@ -153,7 +154,7 @@ class GridView extends BaseListView { * ] * ``` * - * 当然,也支持简写成这样:[[DataColumn::attribute|attribute]], [[DataColumn::format|format]], + * 当然,也支持简写成这样:[[DataColumn::attribute|attribute]], [[DataColumn::format|format]], * 或 [[DataColumn::label|label]] options: `"attribute:format:label"`. * 所以上面例子的 "name" 列能简写成这样 : `"name:text:Name"`. * 甚至"format"和"label"都是可以不制定的,因为它们都有默认值。 @@ -194,7 +195,7 @@ class GridView extends BaseListView { public $filterSelector = 'select[name="per-page"]'; /** - * @var type + * @var type */ public $filter; @@ -221,7 +222,15 @@ class GridView extends BaseListView {
{batch} 添加 - + +
+ + +
+
{filter} @@ -262,7 +271,8 @@ HTML; * 初始化必须的属性和每个列对象 * @return */ - public function init() { + public function init() + { parent::init(); if ($this->formatter === null) { $this->formatter = Yii::$app->getFormatter(); @@ -276,21 +286,24 @@ HTML; $this->initColumns(); } - public function run() { + public function run() + { $view = $this->getView(); GridViewAsset::register($view); $this->registerGridJs(); $this->registerIcheckJs(); $this->registerConfirmJs(); + $this->registerExportJs(); parent::run(); } /** * 注册GridView Js */ - protected function registerGridJs() { + protected function registerGridJs() + { $options = Json::htmlEncode(['filterUrl' => Url::to(Yii::$app->request->url), - 'filterSelector' => $this->filterSelector]); + 'filterSelector' => $this->filterSelector]); $id = $this->options['id']; $this->getView()->registerJs("jQuery('#$id').yiiGridView($options);"); } @@ -298,7 +311,8 @@ HTML; /** * 注册icheck Js */ - protected function registerIcheckJs() { + protected function registerIcheckJs() + { $js = <<