【问题标题】:Yii2 GridView add summarytextYii2 GridView 添加摘要文本
【发布时间】:2017-12-31 17:50:02
【问题描述】:

我想在表格摘要中添加summarytext如何实现?

搜索过这个api,但还是看不懂。

我的视图:

 <div>
    <div class="bg-primary text-white">i want to this in summary text</div>
    <?= GridView::widget([
        'dataProvider' => $provider,
        'summaryOptions' => [
            'class' => 'bg-primary text-white',
        ],
        'columns' => [
            'id',
            'address',
            'email',
            [
                'class' => 'yii\grid\ActionColumn',
                'header' => 'button',
                'headerOptions' => ['style' => 'color:#337ab7'],
                'template' => '{update}{delete}',
                'buttons' => [
                'update' => function ($url,$model) {
                    $url = Url::to(['controller/update', 'id' => $model->id]);
                    return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
                                'title' => Yii::t('app', 'lead-update'),
                    ]);
                },
                'delete' => function ($url, $model) {
                    $url = Url::to(['controller/delete', 'id' => $model->id]);
                    return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
                                'title' => Yii::t('app', 'lead-delete'),
                    ]);
                }
                ],
            ],
        ],
    ]);
    ?>
</div>

希望大家能帮帮我,谢谢!

【问题讨论】:

    标签: gridview yii2


    【解决方案1】:

    分配您需要的值和构建函数的 var 以检索您需要的值 将您需要的 var(或函数)分配给页脚 并在您的网格配置中设置 showFooter = TRUE

    <?php 
      $mySummary ="i want to this in summary text";
    
      echo  GridView::widget([
        'dataProvider' => $provider,
        'showFooter'=>TRUE,
        'summaryOptions' => [
            'class' => 'bg-primary text-white',
        ],
        'columns' => [
            'id',
            [
              'attribute' => 'address',
              'footer' => $mySummary,
            ]
    
            'email',
             .....
    

    【讨论】:

      【解决方案2】:

      我找到了我想要的

      'caption'=>'<h2>Javed</h2>',
      'captionOptions' => [
             'class' => 'bg-primary text-white',
      ],
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多