无法在yii2中修复网格视图行高

时间:2017-04-01 07:34:30

标签: php css gridview yii2

我需要在网格视图中修复行高,其中一些表行可能包含大文本。我尝试了很多我搜索过的东西。有时候我的页脚与我的桌子重叠,这也是一个需要考虑的因素(当我试图修复桌面高度时)。 在此先感谢,这是我的代码:

     <?php

use app\models\SearchAppEvent;
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\web\View;

    /* @var $this yii\web\View */
    /* @var $searchModel app\models\SearchAppEvent */
    /* @var $dataProvider yii\data\ActiveDataProvider */

    $this->title = Yii::t('event', 'App Event');
    $this->params['breadcrumbs'][] = $this->title;
    ?>
    <style>
        /*    tr {
                height: 100px;
                text-overflow: ellipsis;
            }
            td {
                height: 50px;
                text-overflow: ellipsis;        
            }
                .myclass{
                    height: 50px;
                    text-overflow: ellipsis;
                }
            .mydiv tr {
                height: 50px;
                text-overflow: ellipsis;                
            }
            .mydiv td {
                height: 50px;
                text-overflow: ellipsis;                
            }*/
    </style>
    <div class="app-event-index">

        <h1><?= Html::encode($this->title) ?></h1>
        <?php // echo $this->render('_search', ['model' => $searchModel]);   ?>

        <p>
            <?= Html::a(Yii::t('event', 'Create App Event'), ['create'], ['class' => 'btn btn-success']) ?>
        </p>
        <div style="height: 80%" class="mydiv">
            <?=
            GridView::widget([
                'dataProvider' => $dataProvider,
                'filterModel' => $searchModel,
    //        'options' => ['style' => ['text-overflow' => 'ellipses']],
    //        'options' => ['style' => 'max-height:30px;',
    //            'max-width:20px;',
    //        ],
                'rowOptions' => ['style' => 'height:70px;',
    //                'width:20px;',
                    'text-overflow:ellipsis;'
                ],
    //        'tableOptions' => ['class' => 'table table-bordered myclass'],
                'columns' => [

                    'title',
                    [
                        'attribute' => 'c_startDate',
                        'value' => function($model, $key, $index, $widget) {
                            return Yii::$app->formatter->asDatetime($model->c_startDate);
                        },
                    ],
                    [
                        'attribute' => 'c_endDate',
                        'value' => function($model, $key, $index, $widget) {
                            if ($model->c_endDate !== NULL) {
                                return Yii::$app->formatter->asDatetime($model->c_endDate);
                            } else
                                return "غير محدد";
                        },
                    ],
    //            'c_explanation:ntext',
                    [
                        'attribute' => 'c_explanation',
                        'format' => 'raw',
    //                'value' => function ($data) {
    //                    return $data->c_answer;
    //                },
                        'contentOptions' => [
                            'style' =>
                            ['text-overflow' => 'ellipses', 'height' => '100px'],
                        ]
                    ],
                    [
                        'attribute' => 'c_image',
                        'format' => 'html',
                        'value' => function ($data) {
                            return Html::img(Yii::getAlias('@web') . '/img/event/' . $data['c_image'], ['width' => '70px']);
                        },
                            ],
                            [
                                'attribute' => 'c_show',
                                'format' => 'html',
                                'value' => function ($data) {
                                    if ($data->c_show == 1) {
                                        return Html::img(Yii::getAlias('@web') . '/img/all/true.png', ['width' => '30px']);
                                    }
                                    return Html::img(Yii::getAlias('@web') . '/img/all/no.jpg', ['width' => '30px']);
                                },
                                    ],
                                    ['class' => 'yii\grid\ActionColumn'],
                                ],
                            ]);
                            ?>
        </div>
    </div>

1 个答案:

答案 0 :(得分:0)

我添加了一个从文本中删除溢出的函数,并保留前200个字符。 这不是最佳解决方案,但我已经完成了网站。