使用不带表单的按钮在gridview yii2中搜索

时间:2017-01-20 08:56:17

标签: php gridview yii2

我有一个pjax的gridview。

<div class="request-index">
<div id="ajaxCrudDatatable">
    <?=
    GridView::widget([
        'id' => 'crud-datatable',
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'pjax' => true,
        'columns' => require(__DIR__ . '/_columns.php'),
        'toolbar' => [
            ['content' =>
                Html::a('<i class="glyphicon glyphicon-plus"></i> Add Request', ['create'], ['role' => 'modal-remote', 'title' => 'Create new Requests', 'class' => 'btn btn-success']) .
                Html::a('<i class="glyphicon glyphicon-repeat"></i> Reload', [''], ['data-pjax' => 1, 'class' => 'btn btn-primary', 'title' => 'Reset Grid']) .
                '{toggleData}' .
                '{export}'
            ],
        ],
        'panel' => [
            'type' => 'primary',
            'heading' => '<i class="glyphicon glyphicon-list"></i> Requests listing',
            'before' => '<button type="button" class="btn btn-danger btn-secondary"> Belum Selesai : <strong>'.  $count_request_belum_selesai .'</strong> </button>',
            'after' => BulkButtonWidget::widget([
                'buttons' => Html::a('<i class="glyphicon glyphicon-trash"></i>&nbsp; Delete All', ["bulk-delete"], [
                    "class" => "btn btn-danger btn-xs",
                    'role' => 'modal-remote-bulk',delete this item'
                ]),
            ]) .
            '<div class="clearfix"></div>',
        ]
    ])
    ?>
</div>

如果您从上面的代码中看到,请关注

'before' => '<button type="button" class="btn btn-danger btn-secondary"> Not finished : <strong>'.  $count_request_belum_selesai .'</strong> </button>',

单击此按钮时,我想在名为RequestSearch的模型中运行一个函数:

 public function searchRequestBelumSelesai(){
    $query = Request::findAll(['tanggal_selesai' => NULL]);
    return $query;
}

哪个是gridview会显示结果,是否可能?

1 个答案:

答案 0 :(得分:1)

在接收单击按钮的控制器的操作中,您必须修改为View提供的dataProvider,使其看起来像这样:

$dataProvider= new ActiveDataProvider([
    'query' => $your_model->searchRequestBelumSelesai(),
]);