YII CListView Ajax多个TextField过滤器

时间:2014-02-24 15:14:59

标签: ajax yii

我有一个CListView,我想用Ajax过滤。我有2个文本域。现在他们都过滤了同一列:titel。我现在正在寻找相当长的一段时间,但我似乎无法弄清楚为什么他们都过滤掉了标题而不是过去的地方..

这是我第一次使用Ajax,恐怕我现在还不确切知道如何传递正确的参数而且有点丢失。有人可以帮助我吗?

所以这是我的观点:

<?php echo CHtml::beginForm(CHtml::normalizeUrl(array('kunstwerk/index')), 'get', array('id'=>'filter-form'))?>

<?php echo CHtml::textField('string', (isset($_GET['string'])) ? $_GET['string'] : '', array('id'=>'locatie'));?>

<?php echo CHtml::textField('string', (isset($_GET['string'])) ? $_GET['string'] : '', array('id'=>'titel'));?>

和..

Yii::app()->clientScript->registerScript('search',
        "var ajaxUpdateTimeout;
        var ajaxRequest;

        $('input#titel').keyup(function(){
            titel = $(this).serialize();
            clearTimeout(ajaxUpdateTimeout);
            ajaxUpdateTimeout = setTimeout(function () {
                $.fn.yiiListView.update(
        // this is the id of the CListView
                    'ajaxListView',
                    {data: titel}
                )
            },
        // this is the delay
            300);
        });

        $('input#locatie').keyup(function(){
            locatie = $(this).serialize();
            clearTimeout(ajaxUpdateTimeout);
            ajaxUpdateTimeout = setTimeout(function () {
                $.fn.yiiListView.update(
        // this is the id of the CListView
                    'ajaxListView',
                    {data: locatie}
                )
            },
        // this is the delay
            300);
        });"
    );

和..

<?php $this->widget('zii.widgets.CListView', array(
        'dataProvider'=>$dataProvider,
        'itemView'=>'_view',
        'sortableAttributes'=>array(
            'titel'
        ),
        'id'=>'ajaxListView',
    )); 
?>

这是我的控制器:

public function actionIndex($string = '')
    {
        $criteria = new CDbCriteria();
        if( strlen( $string ) > 0 )
            $criteria->addSearchCondition( 'titel', $string, true, 'OR' );
            $criteria->addSearchCondition( 'locatie', $string, true, 'OR' );

        $dataProvider = new CActiveDataProvider( 'Kunstwerk', array( 'criteria' => $criteria, ) );

        //$dataProvider=new CActiveDataProvider('Kunstwerk');
        $this->render('index',array(
            'dataProvider'=>$dataProvider,
            'bedrijven' => Bedrijf::model()->findAll(),
        ));
    }

0 个答案:

没有答案