使用yii \ grid \ CheckboxColumn过滤Javascript Gridview

时间:2015-01-24 01:24:34

标签: javascript php gridview yii2

我有一个问题yii2,我正在使用yii2-grid,我创建了一个按钮来过滤选定的行,我知道如何验证是否已选中,但不知道如何在网格视图的js中应用过滤器选定的行。

我的代码视图(索引):

<?php
    use yii\helpers\Html;
    use kartik\grid\GridView;

    /* @var $this yii\web\View */ 
    /* @var $searchModel frontend\models\HorariosSearch */
    /* @var $dataProvider yii\data\ActiveDataProvider */

    $this->title = Yii::t('check', 'Horarios');
    $this->params['breadcrumbs'][] = $this->title;
?>

<div class="horarios-index">
    <?php echo GridView::widget([
        'id' => 'kv-grid',
        'dataProvider'=> $dataProvider,
        'filterModel' => $searchModel,
        'pjax'         =>true,
        'pjaxSettings' =>[
            'neverTimeout' => true,
        ],
        'hover' => true,
        'responsive' => true,
        'columns' => [
            'id',
            'nombre',
            'tipo',
            [
                'class' => 'kartik\grid\ActionColumn',
                'template' => '{update} {delete}',
            ],
            [
                'class'       => '\kartik\grid\CheckboxColumn',
                'checkboxOptions' => [
                    'class' => 'simple'
                ],
                'pageSummary' => true,
                'rowSelectedClass' => GridView::TYPE_SUCCESS,
            ],
        ],
        'toolbar' => [
            ['content'=>
                Html::a('<i class="ion-plus-round"></i>', ['create'], ['data-pjax'=>false, 'class' => 'btn btn-success', 'title'=>Yii::t('check', 'Crear Horarios')]) . ' ' .
                Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], ['data-pjax'=>false, 'class' => 'btn btn-warning', 'title'=>Yii::t('kvgrid', 'Reset Grid')])
            ],
            '{export}',
            '{toggleData}',
        ],
        'panel' => [
            'type' => GridView::TYPE_PRIMARY,
            'heading' => '<span class="fa ion-android-time fa-lg"></span></span>&nbsp;&nbsp;' . $this->title,
             /* Button Code Selected Rows */
            'footer' => Html::button('<i class="glyphicon glyphicon-download-alt"></i><span>&nbsp;&nbsp; Filter Rows Select</span>',
                ['type'=>'button', 'class'=>'btn btn-success',
                'onclick'=>'var keys = $("#kv-grid").yiiGridView("getSelectedRows").length; alert(keys > 0 ? "Ha Seleccionado: " + keys + " Registros para Filtrar." : "No hay registros Seleccionados para Filtrar.");'
            ]),
        ],
        'exportConfig' => [
            GridView::CSV => ['label' => 'Guardar en CSV'],
            GridView::EXCEL => ['label' => 'Guardar en EXCEL'],
            GridView::PDF => ['label' => 'Guardar en PDF'],
        ]
    ]) ?>
</div>

0 个答案:

没有答案