/ yii2

yii2-grid

Grid 是 Yii2 中列表页面的视图助手类。

<?php

use yii\grid\GridView;

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns'      => [
        ['class' => 'yii\grid\SerialColumn'],

        'id',
        'category_id',
        'name',
        [
                'label' => Yii::t('shop', 'Company'),
                'format'=>'raw',
                'value' => 'company'
        ],
        [
                'attribute' => 'remark',
                // 设置内容最大显示宽度
                'contentOptions'=>['style'=>'max-width: 100px;'],
            ],
        [
                'attribute' => 'content',
                // 这只内容显示固定宽度
                'contentOptions' => ['style' => 'width:200px; white-space: normal;'],
            ],
        [
            'class' => DataColumn::class, // this line is optional
            'attribute' => 'slug',
            'value'     => function ($model) {
                return '/'. $model->category['slug'] . '/'. $model->slug;
            },
            'label' => '别名 - 一个导航如果需要指向内容页面,请复制到导航的路由',
        ],
        'created_at:datetime',
        'updated_at:datetime',

        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>