在仪表板上我想列出具有详细信息的员工,我正在尝试在<div class="col-lg-4" style="border:solid 1px;">
中创建表格,但此处无法设置宽度高度。
答案 0 :(得分:1)
我会举例说明ActiveDataProdvider
:
控制器:
public function actionCustomers(){
$query = new \yii\db\Query;
$query->select('*')
->from('customers')
->limit(10);
$query->createCommand();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => false,
]);
return $this->render('customers', [
'dataProvider' => $dataProvider
]);
}
观点:
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel app\models\CustomersSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Customers';
?>
<div class="customers-index">
<div class="grids">
<div id="customers-grids">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'image',
'format' => 'html',
'label' => 'Profile Image',
'value' => function ($data) {
return Html::img('@web/images/customers/' . $data['image'],
['width' => '96px']);
},
],
'id',
[
'attribute' => 'fullName',
'format' => 'raw',
'label' => 'Customer Full Name',
'value' => function ($data) {
return $data['firstname']." ".$data['lastname'];
},
],
'phone',
'email:email',
[
'attribute' => 'customerBookings',
'format' => 'raw',
'label' => 'No. of Bookings',
'value' => function($data){
return "12 Bookings<br/>8 Orders";
},
],
['class' => 'yii\grid\ActionColumn', 'header'=>'Action'],
],
]); ?>
</div>
</div>
<p class="add">
<?= Html::a('', ['create'], ['class' => '']) ?>
</p>
</div>
注意:我在GridView
小部件中使用了一些自定义列。