issues with CGridView: Filters

Hi All.

not sure where to start with this one… I have a gridview in a legacy system I inherited the task of looking after. I have a certain area where a the gridview results are output, and I need to be able to place filters at the top, and I am not having much success. I have tried a few options, but nothing seems to fully work.

I can get the filter boxes to appear, but when something is searched, the loading symbol appear but the filtering never occurs. The code in question is a little off, but I can’t quite put my finger on why. so I was hoping by putting the snippets below, someone might have an idea. thanks for any help in advance!

here is the code for the gridview:





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

		'id' => 'contact-grid',

		 'dataProvider' => $dpNotPart,

		// 'filter' =>$contact,

		 'enableSorting' => true,

		 'selectableRows' => 10,

		 'summaryText' => '{start}-{end} of {count} Records',

		 'template' => ' {items} {summary} {pager}',

		'columns' => array(

			array(

				'name' => 'ContactID',

				 'id' => 'chk',

				 'value' => 'CHtml::checkBox("ContactIDs1[]",null,array("value"=>$data->ContactID,"id"=>$data->ContactID))',

				 'type' => 'raw',

				 'htmlOptions' => array('width' => 5),

			),

			'Reference', 

			'Name',

			array(

				'name' => 'OrganisationID',

				 'value' => '$data->OrgName',

				 'type' => 'raw',

				 'htmlOptions' => array('width' => 5),

			),

			'DoB',

			'Address1',

			'Address3'

		),

	)

); 




I have been playing around with the filter/dp provider, but it either generates errors or loses the conditions that narrow down the content initially

from the activity controller (this is a list of contacts to add to this activity), the following call generates the content for the gridview - specifically the ‘dpNotPart’ in this instance.





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

            'model' => $this->loadModel($id),

                       //'contact'=>$contact,

            'dpPart' => Contact::findInActivity($model->ActivityID),

            'dpNotPart' => Contact::findNotInActivity($model->ActivityID),

        ));




This will call for a list of those not in the activity. the function it calls is contained within the contact model and has been created as such:





  public static function findNotInActivity($id) {

        $pgSize = 0;

      	//Building condition string bit by bit. only have people who are not deceased, related to the activity, and has a valid registration record

		$condition= ' contactid IN (select contactid from registration b';

		$condition.=' WHERE contactid = b.contactid';

		$condition.=' AND (b.leavedate IS NULL OR b.leaveDate> CURDATE()))';

		$condition.=' AND ContactID Not In (Select ContactID From contactactivity WHERE ActivityID =' . $id . ')';

		$condition.=' AND  (Deceased IS NULL OR Deceased=0)';

		$condition.=' AND projectid = ' . Activity::model()->findByPK($id)->programme->ProjectID;


        $model = Contact::model()->findAll($condition);

        /* added again on 04/04/2013 -> removed on 13/2/13 as pagesize too big as model count>1000 contacts */

        if ($model)

            if (count($model)>500)

                $pgSize=500;

            else

                $pgSize=count($model);




        $sort = new CSort();

        $sort->defaultOrder = 'Surname, Firstname';

        $sort->attributes = array(

            'Name' => array(

                'asc' => 'Surname, Firstname',

                'desc' => 'Surname desc, Firstname desc',

            ),

            'Reference',

        );


		//use the condition built above

        $dp = new CActiveDataProvider('Contact', array(

                    'sort' => $sort,

                    'pagination' => array(

                     //'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),

                       'pageSize' => $pgSize,

                    ),

                    'criteria' => array(

                        'condition' => $condition,


                    ),

                ));

        return $dp;

    }




once i try to bring in filters to this gridview however, its either error messages or filters that dont seem to do anything at all. I’m still relatively new to yii, so its possible i am overlooking something, and i am completely open to suggestion before this drives me completely crazy. This system definitely has a lot of quirks and workarounds as can be expected in a handed down system, so if the approach in it is completely wrong, im not against rewriting full elements.

thanks