My problem is, I want to customize the drop-down list of autocomplete.Below is my tried code but it is not displaying as I want.
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'autoComplete',
'value'=>'',
'source'=>$this->createUrl('post/search'),
// additional javascript options for the autocomplete plugin
'options'=>array(
'showAnim'=>'fold',
),'htmlOptions'=>array(
//'onfocus' => 'js: this.value = null; $("#searchbox").val(null); $("#selectedvalue").val(null);',
'class' => 'input-xxlarge search-query',
'placeholder' => "Search...",
'methodChain'=>'.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.name + "</a>" )
.appendTo( ul );
};'
),
));
?>
It should create <li>
and append <a></a>
to it without any class. But it is not working and displaying the default drop-down list.
Thanks
This is the image of the result which i was getting previously.
And my desired result is
So first of all I changed the function which was giving me only one column's data. This is the code from my controller.
To accomplish to process the multiple column data result we require our own widget which will give us option to process that result. This code I have taken from here.
Where to save this file?
Code
Now you have created an extension here and now you can use it in your view.
Code for View
Now you have noticed that I have used methodChain option in autocomplete widget to add extra content in drop-down. This feature we get because we have used our new customised autocomplete widget.
The classes are set by the jQuery autocomplete so this isn't specific to Yii. Unfortunately you cannot override them like that.
You can either create your own custom CSS for the classes it uses as explained here: Jquery autocomplete styling
Or work with the 'open' method to modify the style when the dropdown is opened. That's also explained under the link above but further down.
Update: Based on the linked answer and using your example you could change the background-color for the
<li>
elements using this:That means you can change the styles on the fly but you can't get rid of the classes completely as they are hard-coded into the jQuery method.
You could also use ThemeRoller to create your own custom theme for the autocomplete.