Hello everyone!
I would like to learn how you can implement the following problem:
I need to create widget with kinda live filtering (user typing smth. in input field and widget load filtered data).
For example:
in Index view (which use actionIndex of SiteController) I use widget (<input> + ClistView with pagination).
Widget goal: load filtered CListView (when user typing some words in <input> … ajax takes place and loads new ClistView which now contains filtered data)
But Widget runs from actionUpdateAjax of SiteController (not actionIndex) to load filtered data and it causes several problems:
- Initially, the widget runs in the Site/Index
and links in pagination looks like /site/Index?page=2
because dataProviderConv first cretaes in renderContent method in widget:
//convList widget
protected function renderContent()
{
$dataProviderConv=$this->loadconv();
$this->render('convList', array(
'dataProviderConv'=>$dataProviderConv,
'data' => $data,
));
but after updating via ajax: links in pagination looks like /site/UpdateAjax?page=2 (because widget run from UpdateAjax action of SiteController)
How could I fix this problem?
- I tried to fix it using this code:
//_ajaxContent view
$dataProviderConv->setPagination(array(
'route'=>$route, //$route looks like 'controller/view'
));
It didn’t work properly
- of course I could use actionIndex to load filtered data… but in this way I need to rewrite all controllers (in wich I want to use widget) to add UpdateAjax functionality
[b]Main question:
Is there any way to load (reload) filtered CListView with pagination in widget (using ajax)? If I create dataProvider for CListView in other controller[/b]
//convList widget view:
<?php if (Yii::app()->request->isAjaxRequest): ?>
<div id="data" style='clear:both;'>
<?php
$this->render('_ajaxContent', array(
'dataProviderConv'=>$dataProviderConv,
)
, false, true);
?>
</div>
<?php else: ?>
echo CHtml::textField(
'search_input_field',
'start typing to filter...',
array(
'id'=>'search_input',
'class'=>"searchbox_text_tt",
'onkeyup'=>CHtml::ajax(
array(
'type'=>'POST',
'url'=> Yii::app()->createUrl('site/UpdateAjax'),
'update'=>'#data',
'data'=>'js:jQuery(this).serialize()'
)
),
)
);
?>
<div id="data" style='clear:both;'>
<?php
$this->render('_ajaxContent', array(
'myValue'=>$myValue,
'dataProviderConv'=>$dataProviderConv,
), false, true);
?>
</div>
<?php endif; ?>