Hallo zusammen,
ich habe ein Problem mit CListView. Ich gebe mit CListView eine Liste von Items aus. Habe dann ein Suchfeld hinzugefügt mit dem der DataProvider aktuallisiert wird. Funktioniert auch super, ABER wenn ich dann die Sortierfunktion des Widgets nutzen möchte zeigt er mir wieder die ursprünglichen Daten an und nicht das Suchergebnis.
Hat da jemand eine Idee?
Hier der Code:
Controller:
public function actionIndex() {
$dataProvider=new CActiveDataProvider('animal', array(
'criteria'=>array(
'condition'=>'name LIKE :name',
'params'=>array(':name'=>'%'.$_POST['search_field'].'%'),
),
'pagination'=>array(
'pageSize'=>self::PAGE_SIZE,
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
View:
<?php
$this->breadcrumbs=array(
'Animals',
);
?>
<h1>Tiere</h1>
<ul class="actions">
<li><?php echo CHtml::link('Neues Tier anlegen',array('create')); ?></li>
<li><?php echo CHtml::link('Tiere verwalten',array('admin')); ?></li>
</ul><!-- actions -->
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::Label('Suche: ','Suche'); ?>
<?php $this->widget('CAutoComplete',array(
//name of the html field that will be generated
'name'=>'search_field',
//replace controller/action with real ids
'url'=>array('animal/autocompletelookup'),
'max'=>10, //specifies the max number of items to display
//specifies the number of chars that must be entered
//before autocomplete initiates a lookup
'minChars'=>2,
'delay'=>500, //number of milliseconds before lookup occurs
'matchCase'=>false, //match case when performing a lookup?
//any additional html attributes that go inside of
//the input field can be defined here
'htmlOptions'=>array('size'=>'40'),
));
?>
<?php echo CHtml::submitButton('Suchen'); ?>
<?php echo CHtml::endForm();?>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'sortableAttributes'=>array(
'name',
'skill',
'price',
),
));