简体   繁体   English

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

[英]Search in gridview yii2 using a button not with form

I have a gridview with pjax. 我有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>

if you see from code above, please concern with 如果您从上面的代码中看到,请关注

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

When this button is clicked, I want to running a function in my model named RequestSearch : 单击此按钮后,我想在名为RequestSearch的模型中运行一个函数:

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

Which is the gridview will be displayed the result, is it possible ? 结果将显示在哪个gridview中,可能吗?

In the action of the controller that will receive the click of your button, you must modify the dataProvider given to the View, so that it looks like something like this: 在将收到按钮单击的控制器的操作中,必须修改提供给View的dataProvider,使其看起来像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM