YII CListView Ajax多文本字段过滤器
我有一个CListView,我想用Ajax过滤它。我有两个文本字段。现在它们都过滤同一列:滴度。我已经搜索了很长一段时间了,但我似乎不明白为什么他们都过滤滴度而不是位置 这是我第一次使用Ajax,所以我现在恐怕不知道如何传递正确的参数,我有点迷路了。谁能帮我 因此,我的观点如下:YII CListView Ajax多文本字段过滤器,ajax,yii,Ajax,Yii,我有一个CListView,我想用Ajax过滤它。我有两个文本字段。现在它们都过滤同一列:滴度。我已经搜索了很长一段时间了,但我似乎不明白为什么他们都过滤滴度而不是位置 这是我第一次使用Ajax,所以我现在恐怕不知道如何传递正确的参数,我有点迷路了。谁能帮我 因此,我的观点如下: <?php echo CHtml::beginForm(CHtml::normalizeUrl(array('kunstwerk/index')), 'get', array('id'=>'filter-f
<?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'));?>
和
ajax请求会转到actionindex吗?嗯,我认为应该,但另一方面我认为不会。过滤器位于索引页上。但是,如果我删除操作索引上的条件,它仍然以相同的方式工作。但我不知道他现在从哪里获得信息来过滤“titel”字段……发现他总是比较我数据库表中的第一个varchar列,即“titel”。有人知道我如何比较另一列吗?好的,请将这一行添加到您的代码CVarDumper::Dump($criteria,100,true);模具();设置搜索条件后。并查看正在执行的sql查询。谢谢,我添加了您的行,当我刷新/回发页面时,该行会起作用。当ajaxrequest被激发时,它不会在我的模型中运行actionIndex或搜索功能。所以我真的很困惑,不知道它在哪里设置sql命令。所以它激发并给出结果,但我无法控制正确的数据库列。。
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(),
));
}