I’m using tab widgets of jQueryUI. Each tab contains a CGridview table with its own filter. One of the tabs fetches its content via Ajax.
Controller:
public function actionIndex()
{
$model=new Admin('search');
$model->unsetAttributes();
if(isset($_GET['Admin']))
$model->attributes=$_GET['Admin'];
$this->render('index',array('model'=>$model));
}
public function actionPartners()
{
$model=new Partner('search');
$model->unsetAttributes();
if(isset($_GET['Partner']))
$model->attributes=$_GET['Partner'];
$this->renderPartial('partners',array('model'=>$model));//render contents for tab-2
}
View of index:
<ul>
<li><a href="#admin_tab_admins">Admins</a></li>
<li><a href="admin/partners.html" title="partners">Partners</a></li> //get contents of tab-2 via ajax
</ul> //here will generate 2 tabs
//contents for tab-1
<div id="admin_tab_admins">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'id'=>'admin_table',
'columns'=>array(
array(
'header'=>'ID',
'name'=>'adminID',
),
array(
'header'=>'Username',
'name'=>'userName',
),
...
)
));
?>
</div>
View of partner:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'id'=>'partner_table',
'columns'=>array(
array(
'header'=>'ID',
'name'=>'partnerID',
),
array(
'header'=>'Partner Name',
'name'=>'partnerName',
),
...
)
));
?>
After getting the CGridView of tab-2 via ajax, there are 2 CGridView on the same page. The filter of tab-2’s CGridView will not work.
This thread does not solve my problem because I have set different ID for each CGridView, and I use different model.
I think the problem is that the CGridView filter of tab-2 post data to filter of tab-1’s url. I found the following js code, which is generated by tab-1’s CGridView:
jQuery('#admin_table').yiiGridView({'ajaxUpdate':['admin_table'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items','selectableRows':1,'pageVar':'Admin_page'});
However, no js code was found for tab-2’s CGridView, which is shown via ajax.
Any ideas?