Difference between #1 and #2 of
Filter / Search with CListView

Revision #2 has been created by Maurizio Domba Cerin on Sep 2, 2011, 7:37:14 AM with the memo:

adjusted code indent
« previous (#1) next (#3) »

Changes

Title unchanged

Filter / Search with CListView

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

filter, CListView, CGridView, search

Content changed

[...]
This is what I did. Its the EASIEST solution that I know of. I just reused the advanced search done in CGridView.

<b>In my controller file</b>


 
 
```php public function actionIndex() {             
 
            
$model=new Blogs('search');     $model->unsetAttributes(); // clear any default values     if(isset($_GET['Blogs']))         $model->attributes=$_GET['Blogs'];     //send model object for search
 
  
$this->render('index',array(
 
        
'dataProvider'=>$model->search(),
 
       
'model'=>$model)); //send model object for search
 
            

 
    ); 
 
} ```
 

 
<b>In my view file</b> (namely my index file)
[...]
<?php
$this->breadcrumbs=array(
    'Blogs', ); $this->menu=array(     array('label'=>'Create Blogs', 'url'=>array('create')),     array('label'=>'Search Blogs', 'url'=>array('admin')), ); Yii::app()->clientScript->registerScript('search', " $('.search-button').click(function(){     $('.search-form').toggle();     return false; }); $('.search-form form').submit(function(){     $.fn.yiiListView.update('blogslistview', {
 
        
//this entire js section is taken from admin.php. w/only this line diff         data: $(this).serialize()     });     return false;
});
");
[...]
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
    'model'=>$model, )); ?> </div> <?php $this->widget('zii.widgets.CListView', array(     'dataProvider'=>$dataProvider,     'itemView'=>'_view',     'id'=>'blogslistview',       // must have id corresponding to js above     'sortableAttributes'=>array( 'id', 'startdate',    'enddate',     'user_id', ), )); ?> ```
22 0
26 followers
Viewed: 55 340 times
Version: 1.1
Category: How-tos
Written by: JohnPollard
Last updated by: JohnPollard
Created on: Sep 1, 2011
Last updated: 11 years ago
Update Article

Revisions

View all history