activeCheckboxList

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

ok, I solve the first problem, now I can filter the result, I put the code here for everywere who is searching this

Now i try to put a second criteria but this when i do I post it

view




<?php

Yii::app()->clientScript->registerScript('search',

    "var ajaxUpdateTimeout;

    var ajaxRequest;

   	$('.categoryFilter').change(function(){

    categoria_id = $('.categoryFilter').serialize();

	marca_id = $('.marcaFilter').serialize();

    $.fn.yiiListView.update(

     	'ajaxListView',

                {

		 url: '" . CController::createUrl('Post/index') . "',

		 data: categoria_id

                }

    );

});"

);


echo CHtml::activeCheckboxList(

  $model, 'categoria_id', 

  CHtml::listData(Categoria::model()->findAll(), 'id', 'name'),

  array('template'=>'<li>{input} {label}</li>',  'class'=>'categoryFilter',)

);




$this->widget('zii.widgets.CListView', array(

	'id'=>'ajaxListView',

    'dataProvider'=>$dataProvider,

    'itemView'=>'_view',

	//'filter'=>$model->search(),

    'sortableAttributes'=>array(

        'id',

		'title',

		'categoria_id'

    ),

    

));

?>




controller




public function actionIndex()

{

	

	$categoria_id = (isset($_GET['Post']['categoria_id'])) ? $_GET['Post']['categoria_id'] : array();

	CVarDumper::dump($categoria_id);

	

	$model=new Post();

    $criteria = new CDbCriteria();

 

    if( count( $categoria_id ) > 0 )

		$criteria->addInCondition( 'categoria_id', $categoria_id );

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

    	$this->render( 'index', array( 

			'dataProvider' => $dataProvider,

			'model'=>$model, 

			));

	

		

	}



how to set two checkboxes per row in activecheckboxlist?

this is really very good…

i did it…

here use the 2 table but i have 3 table. it works for the individual one but not together.here i use 2 variable .both variable work and it search for individual individual not together.when one variable is store data in array then another become empty and vice verse .how to both variable store data together in array?

pls help me?

any help which is appreciated to me…

thanks in advance…

here is my code:

in controller:


        public function actionIndex()

	{

    $master_key = (isset($_GET['ProductIndex']['master_key'])) ? $_GET['ProductIndex']['master_key'] : array();

    $product_id = (isset($_GET['ProductIndex']['product_id'])) ? $_GET['ProductIndex']['product_id'] : array();

    CVarDumper::dump($master_key,$product_id);

	 $model = new ProductIndex();

    $criteria = new CDbCriteria();

	if( count( $master_key ) > 0 )

	{

	$criteria->addInCondition( 'master_key', $master_key );  

	}

   	if( count( $product_id ) > 0 )

	{

	$criteria->addInCondition( 'product_id', $product_id );  

	}

	$dataProvider = new CActiveDataProvider('ProductIndex',

	array('criteria'=>$criteria

                        ), array(

					'criteria' => array(

					'with' => 'pricing',

					'with' => 'masterKey',

					)));

             $this->render('index',array(

            'dataProvider'=>$dataProvider,

			'model'=>$model,

			'master_key'=>$master_key,

			'product_id'=>$product_id,

            ));

			}

in view.

index.php:




<?php

Yii::app()->clientScript->registerScript('search',

    "var ajaxUpdateTimeout;

    var ajaxRequest;

		$('.masterindexFilter').change(function(){

	master_key = $('.masterindexFilter').serialize();

    $.fn.yiiListView.update(

        'ajaxListView',

                {

                 url: '" . CController::createUrl('productindex/index') . "',

                 data: master_key,

				

			 }

    );

}),

		$('.mblspecificationFilter').change(function(){

    product_id = $('.mblspecificationFilter').serialize();

    $.fn.yiiListView.update(

        'ajaxListView',

                {

                 url: '" . CController::createUrl('productindex/index') . "',

                 data: product_id,

				

			 }

    );

}

);"


);

?>

<?php

echo CHtml::activeCheckboxList(

 $model,  'master_key', 

  CHtml::listData(MasterIndex::model()->findAll(), 'master_key', 'brand'),

  array('template'=>'<li>{input} {label}</li>',  'class'=>'masterIndexFilter',)

);

?>

<h4>OS:</h4>

		<?php

echo CHtml::activeCheckBoxList($model,'product_id',

//$model->getOsOptions() 'product_id', 'platform_os',

CHtml::listData(MblSpecification::model()->findAll(), 'product_id', 'platform_os'),

		array( 'template'=>'<li>{input} {label}</li>',  'class'=>'mblspecificationFilter',)); 

		?>

        


<?php

 $this->widget('zii.widgets.CListView', array(

'dataProvider'=>$dataProvider,

'itemView'=>'_new',

'id'=>'ajaxListView',

)); 

?>