Yii2上的GridView:如何冻结标题(即,有一个固定的标题行)

时间:2018-03-26 08:11:44

标签: php gridview yii yii2

有没有办法在Yii2中修复GridView标题行?

Yii2和GridView相当新,并进行了一些搜索,但似乎没有直截了当的答案。

JSFiddle拥有我正在处理的完整代码:https://jsfiddle.net/farablanco/cf0zs4uc/

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'rowOptions' => function($model){
        },
        'columns' => [
            // 'slug',
            ['class' => 'yii\grid\SerialColumn'],
            ['attribute' => 'title',
             'format'=>'raw',
             'value' => function($data){
                return
                Html::a($data->title, '/stock-page/?slugparam=' . $data->slug, ['class'=>'title-link', 'target'=>'_blank']);
             },
             'contentOptions' => ['class' => 'title'],
             ],
            ['attribute' => 'gpa',
             'label' =>'GPA',
             'contentOptions' => ['class' => 'gpa'],
             ],
            ['attribute' => 'dividend_yield',
             'label' =>'Dividend Yield',
             'contentOptions' => ['class' => 'dividend_yield'],
             ],
           ...
        ],
    ]); ?>

1 个答案:

答案 0 :(得分:0)

您可以使用此扩展程序http://demos.krajee.com/grid, 它是一个很棒的扩展,有很多选项,简单易用,只需添加         'floatHeader'=&gt; false即

echo GridView::widget([
'dataProvider'=> $dataProvider,
'filterModel' => $searchModel,
'floatHeader'=>false,
'floatHeaderOptions'=>['scrollingTop'=>'50'] ......