1

I have index.php made by the Gii tool that created a CRUD. Also I use AdminLTE template.

It has the GridView that should show two columns: "Phrase" and "Author" but the column "Phrase" has some rows with long text (around 350 characters) so just a part of this column is shown. And the "Author" column is not shown at all.

There is no horizontal scroll bar (it should help me):

enter image description here

Or maybe the problem is the string data type:

public function rules()
{
    return [
        [['phrase'], 'required'],
        [['phrase'], 'string'],
        [['author'], 'string', 'max' => 50],
    ];
}

This is my index.php view:

<div class="box box-primary">
    <?php Pjax::begin(); ?>                
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            'phrase',
            'author',
        ],
    ]); ?>
    <?php Pjax::end(); ?>
</div>
Roby Sottini
  • 2,117
  • 6
  • 48
  • 88

3 Answers3

3

You can also use contentOptions :

[
   'attribute' => 'phrase',
   'contentOptions' => [
       'style' => [
           'max-width' => '600px',
           'white-space' => 'normal',
       ],
   ],
],
Insane Skull
  • 9,220
  • 9
  • 44
  • 63
2

I added the table-responsive class to <div class="box box-primary">

<div class="box box-primary table-responsive">
    <?php Pjax::begin(); ?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            'frase',
            'autor',
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{update} {delete}'
            ],
        ],
    ]); ?>
    <?php Pjax::end(); ?>
</div>
Roby Sottini
  • 2,117
  • 6
  • 48
  • 88
0

Try This:

[
    'attribute'=>'phrase',
    'value'=>function($data){
        return strlen($data->phrase) > 100 ? Html::encode(substr($data->phrase, 0, 100)) . ". . ." : $data->phrase;
    }
]

It will display the first 100 characters from the string, if the string size is greater than 100.

Set The Value according to your desired width.

Pratik Karmakar
  • 247
  • 1
  • 8