Browse Source

grid view 添加页数选择

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

26
common/models/CategorySearch.php

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

1
kcadmin/assets/AppAsset.php

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

2
kcadmin/views/category/create.php

@ -14,7 +14,7 @@ $this->params['breadcrumbs'][] = $this->title;
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
'model' => $model,
]) ?>
</div>

3
kcadmin/views/category/index.php

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

37
kcadmin/web/css/site.css

@ -30,41 +30,4 @@
.login-form h6 {
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