Browse Source

grid view 添加页数选择

wechat_public_accounts
blobt 5 years ago
parent
commit
8bc0839305
  1. 22
      common/models/CategorySearch.php
  2. 1
      kcadmin/assets/AppAsset.php
  3. 3
      kcadmin/views/category/index.php
  4. 37
      kcadmin/web/css/site.css

22
common/models/CategorySearch.php

@ -9,13 +9,12 @@ use common\models\Category;
/** /**
* CategorySearch represents the model behind the search form of `\common\models\Category`. * CategorySearch represents the model behind the search form of `\common\models\Category`.
*/ */
class CategorySearch extends Category
{
class CategorySearch extends Category {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function rules()
{
public function rules() {
return [ return [
[['id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], [['id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'],
[['cat_name', 'icon', 'description'], 'safe'], [['cat_name', 'icon', 'description'], 'safe'],
@ -25,8 +24,7 @@ class CategorySearch extends Category
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function scenarios()
{
public function scenarios() {
// bypass scenarios() implementation in the parent class // bypass scenarios() implementation in the parent class
return Model::scenarios(); return Model::scenarios();
} }
@ -38,14 +36,21 @@ class CategorySearch extends Category
* *
* @return ActiveDataProvider * @return ActiveDataProvider
*/ */
public function search($params)
{
public function search($params) {
$query = Category::find(); $query = Category::find();
// add conditions that should always apply here // add conditions that should always apply here
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => $query, 'query' => $query,
'pagination' => [
'pageSizeLimit' => [1, 200]
],
'sort' => [
'defaultOrder' => [
'id' => SORT_DESC,
]
],
]); ]);
$this->load($params); $this->load($params);
@ -71,4 +76,5 @@ class CategorySearch extends Category
return $dataProvider; return $dataProvider;
} }
} }

1
kcadmin/assets/AppAsset.php

@ -21,6 +21,5 @@ class AppAsset extends AssetBundle
'yii\bootstrap\BootstrapAsset', 'yii\bootstrap\BootstrapAsset',
'yii\bootstrap\BootstrapPluginAsset', 'yii\bootstrap\BootstrapPluginAsset',
'blobt\web\AdminlteAsset', 'blobt\web\AdminlteAsset',
'blobt\web\DatatableBootstrap'
]; ];
} }

3
kcadmin/views/category/index.php

@ -3,6 +3,7 @@
use yii\helpers\Html; use yii\helpers\Html;
use blobt\grid\GridView; use blobt\grid\GridView;
//use yii\grid\GridView;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $searchModel common\models\CategorySearch */ /* @var $searchModel common\models\CategorySearch */
@ -11,11 +12,13 @@ use blobt\grid\GridView;
$this->title = 'Categories'; $this->title = 'Categories';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<?php <?php
echo GridView::widget([ echo GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterSelector' => 'select[name="per-page"]',
'columns' => [ 'columns' => [
'id', 'id',
'cat_name', 'cat_name',

37
kcadmin/web/css/site.css

@ -31,40 +31,3 @@
.login-form h6 { .login-form h6 {
text-align: center; text-align: center;
} }
/*datatable修改*/
table.dataTable thead > tr > th.sorting_asc, table.dataTable thead > tr > th.sorting_desc, table.dataTable thead > tr > th.sorting,
table.dataTable thead > tr > td.sorting_asc,
table.dataTable thead > tr > td.sorting_desc,
table.dataTable thead > tr > td.sorting {
padding-right: 8px;
}
table.dataTable thead > tr > th > a{
position: relative;
display: block;
color:#333333;
font-family: 'Glyphicons Halflings';
}
table.dataTable thead > tr > th > a:after{
position: absolute;
right: 0px;
opacity: 0.2;
content: "\e150";
}
table.dataTable thead > tr > th > a.asc:after{
position: absolute;
right: 0px;
content: "\e155";
opacity: 0.6;
}
table.dataTable thead > tr > th > a.desc:after{
position: absolute;
right: 0px;
content: "\e156";
opacity: 0.6;
}
Loading…
Cancel
Save