[size=“4”]I’m trying to make a search inputBox and display the result into a list view via AJAX.[/size]
After a lot of research I found this tutorial: CListView AJAX filtering
After try it, on a normal Controller > View, it works perfectly!
[color="#008000"]But I would like to make a portable version of this search by making a widget.[/color]
This is where things get bad.
CInputWidget:
class ImageManager extends CInputWidget
{
public function run($search = "")
{
$criteria = new CDbCriteria();
$criteria->compare('title',$search,true);
$criteria->compare('tags',$search,true,'OR');
return new CActiveDataProvider('Media',
array('criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>'12'
))
);
$this->render("index", array(
"dataProvider"=>$dataProvider
));
}
...
VIEW:
<?php
Yii::app()->clientScript->registerScript('search',
"var ajaxUpdateTimeout;
var ajaxRequest;
$('input#search').keyup(function(){
ajaxRequest = $(this).serialize();
clearTimeout(ajaxUpdateTimeout);
ajaxUpdateTimeout = setTimeout(function () {
$.fn.yiiListView.update(
'mediaViewer',
{data: ajaxRequest}
)
},
500);
});"
);
?>
<input id="search" name="search" type="text" class="search-query col-md-6 pull-right " placeholder="Search">
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'id'=>'mediaViewer',
'itemView'=>'_view',
));
?>
[color="#0000FF"]What I expect:[/color]
To render my listview, enter a string to search and the listview will update with my new list found.
[color="#0000FF"]What I get:[/color]
The listview renders, when I enter a search string, I can see the update process animation but after the search is done, I still see the same list. No changes.
Please note: When the SAME functions are used with a normal controller>view it works like a charm.
[size="3"]
[color="#008000"]Why the $.fn.yiiListView.update() doesn’t fetch and display the proper item via a widget!?[/color][/size]
Any insight would be greatly appreciated