Is there a way to re-render the view that contains CGridView with a custom ‘dataProvider’ option? For example I have such view file
<?php $this->widget('bootstrap.widgets.BootGridView',array(
'id'=>'operations-grid',
'type'=>'striped bordered',
'dataProvider'=>$model->search(),
'columns'=>array(
array('name'=>'operationType','value'=>'$data->operationType->name'),
array(
'name'=>'creation_date','type'=>'datetime'
),
'ammount_usd:raw:Ammount',
'comment:text:Comment',
array(
'name'=>'currency',
'value'=>'$data->currency->short',
),
array(
'name'=>'client',
'value'=>'$data->client->fio'
),
array(
'name'=>'organization',
'value'=>'$data->organization->name'
),
array(
'class'=>'bootstrap.widgets.BootButtonColumn',
'header'=>'Action'
),
),
)); ?>
As a provider I have $model->search(), but I want for example, if a button pressed this view to be re-rendered via ajax with different dataProvider. Is there a way to achieve this? Thanks.
You can do this in several ways.
Among which, you can let the controller provide the view with the $dataProvider, like this:
The controller could instantiate the needed data provider based on the parameters that arrived in that request. The view then just passes this data provider to CGridView, completely oblivion to its precise type.
As already mentioned, you can extend CDataProvider (the same class that CActiveDataProvider extends) to customize it completely as long as it provides the API required by it. See its documentation