Hello, I’m trying to filter results in a CListView using checkbox, after much research, I found activeCheckboxList function.
My problem is that while it appears the preload, it is not filtering the results, and the truth is not good to do.
Am a beginner, although long 7 years ago I program
If someone could help me I’ll be more than grateful.
I tell them I have two tables tbl_post tbl_categorias
tbl_post (id categoria_id title)
tbl_categoria (id name)
At the moment I see the list of checkboxes and ajax runs, but solves nothing, always shows all results.
If someone could give me a hand I’ll be more than grateful
Thank you very much in advance and Up Yii
View/Post/Index.php (view)
<h1>Posts</h1>
<?php
echo CHtml::activeCheckboxList(
$model, 'id',
CHtml::listData(Categoria::model()->findAll(), 'id', 'name'),
array('template'=>'<li>{input} {label}</li>', 'class'=>'categoryFilter',)
);
?>
<?php
Yii::app()->clientScript->registerScript('search',
"var ajaxUpdateTimeout;
var ajaxRequest;
$('.categoryFilter').change(function(){
category = $('.categoryFilter').serialize();
$.fn.yiiListView.update(
'ajaxListView',
{
url: '" . CController::createUrl('Post/index') . "',
data: category
}
);
});
"
);
$this->widget('zii.widgets.CListView', array(
'id'=>'ajaxListView',
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'sortableAttributes'=>array(
'id',
'title',
'categoria_id'
),
));
?>
in the PostController.php
public function actionIndex( array $category = array() )
{
$model=new Categoria();
$criteria = new CDbCriteria();
if( count( $category ) > 0 )
$criteria->addInCondition( 'category', $category );
$dataProvider = new CActiveDataProvider( 'Post', array( 'criteria' => $criteria, ) );
$this->render( 'index', array(
'dataProvider' => $dataProvider,
'model'=>$model,
) );
}
this function I get from http://www.yiiframework.com/wiki/185/clistview-ajax-filtering/
thanksssssssssss