Yii的GridView
生活随笔
收集整理的這篇文章主要介紹了
Yii的GridView
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
示例?
<?php use yii\grid\GridView; echo GridView::widget(['dataProvider' => $dataProvider,'filterModel' => $searchModel,//重新定義分頁樣式'layout'=> '{items}<div class="text-right tooltip-demo">{pager}</div>','pager'=>[//'options'=>['class'=>'hidden']//關閉分頁'firstPageLabel'=>"First",'prevPageLabel'=>'Prev','nextPageLabel'=>'Next','lastPageLabel'=>'Last',]'columns' => [['class' => 'yii\grid\SerialColumn'],// 使用的是模型的列的數據'id','username',[//由于是默認類型,可以省略 'class' => 'yii\grid\DataColumn', 'value' => function ($data) {// 如果是數組數據則為 $data['name'],例如,使用 SqlDataProvider 的情形。return $data->name; },],['label'=>'標題','value' => 'title'],['label'=>'文章內容','format' => 'html','value' => 'content'],[//產生一個a標簽,點擊可排序'label'=>'文章類別', 'attribute' => 'cid', //關聯表'value' => 'cate.cname' ],[//動作列yii\grid\ActionColumn //用于顯示一些動作按鈕,如每一行的更新、刪除操作。'class' => 'yii\grid\ActionColumn','header' => '操作', 'template' => '{delete} {update}',//只需要展示刪除和更新'headerOptions' => ['width' => '240'],'buttons' => ['delete' => function($url, $model, $key){return Html::a('<i class="fa fa-ban"></i> 刪除',['del', 'id' => $key], ['class' => 'btn btn-default btn-xs','data' => ['confirm' => '你確定要刪除文章嗎?',]]);}, ],], ], ]); ?>時間?
['attribute' => 'created_at','format' => 'text','value' => function($data){return date("Y-m-d H:i:s",($data->created_at));}, ], ['attribute' => 'updated_at','format' => 'text','value' => function($data){return date("Y-m-d H:i:s",($data->updated_at));}, ],圖片
['label'=>'封面圖','format'=>'raw','value'=>function($m){return Html::img($m->cover,['class' => 'img-circle','width' => 30]);} ], ['attribute' => 'image','format' => ['image',['width'=>'100','height'=>'100']],'value' ? ? => function ($data) {return $data->image;} ], ['attribute' => 'image','label' ? ? => '圖片顯示','format' => 'raw','value' ? ? => function ($data) {$link = Html::a(Html::img($data->image, ['alt' => 'ImageSource','width' => 100,'height' => 100]),[$data->image]);return $link;} ],鏈接
['attribute' => 'title','value' => function ($model, $key, $index, $column) {return Html::a($model->title, ['article/view', 'id' => $key]);},'format' => 'raw', ],枚舉
['attribute' => 'sex', 'value'=>function ($model,$key,$index,$column){return $model->sex==1?'男':'女'; },//在搜索條件(過濾條件)中使用下拉框來搜索'filter' => ['1'=>'男','0'=>'女'],//or'filter' => Html::activeDropDownList($searchModel,'sex',['1'=>'男','0'=>'女'],['prompt'=>'全部']) ], ['label'=>'產品狀態', 'attribute' => 'pro_name', 'value' => function ($model) {$state = ['0' => '未發貨','1' => '已發貨','9' => '退貨,已處理',];return $state[$model->pro_name];},'headerOptions' => ['width' => '120'] ]value
總結
以上是生活随笔為你收集整理的Yii的GridView的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cad画墙体的双线命令是什么(cad画墙
- 下一篇: cad墙体双线怎么设置比例(cad墙体双