Help With Filters Please My Cgridview Does Not Filter

Hi All

Can some one please help me with my filters, they do not seem to be getting data from the database.

View


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

    'id'=>'user-grid',

    'dataProvider'=>$model->search(),

    'filter'=>$model,

    'enablePagination'=>true,

	'pager'=>array(

        'maxButtonCount'=>'7',

    ),

    'columns'=>array(

		array(

			'name'=>'bt_number',

			'type'=>'raw',

			'value'=>$model->bt_number,


		),

		array(

			'name'=>'date_time',

			'type'=>'raw',

			'value'=>$model->date_time,

		),

                array(

			'name'=>'broker',

			'type'=>'raw',

                        'value'=>$model->broker,

			'filter'=>Yii::app()->params['brokers'],

			

		),

		array(

			'class'=>'CButtonColumn',

			'template'=>'{view}{update}'

		),

    )

));

Model


public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		echo "booker ".$this->broker;// exit;

               //above only displays booker there is nothing in $this->broker

		

		$criteria=new CDbCriteria;


		$criteria->compare('bt_number',$this->bt_number);

		$criteria->compare('sign',$this->sign,true);

		$criteria->compare('fm_buys',$this->fm_buys,true);

		$criteria->compare('fm_buys_amt',$this->fm_buys_amt,true);

		$criteria->compare('against',$this->against,true);

		$criteria->compare('bt_sett_date',$this->bt_sett_date,true);

		$criteria->compare('bt_order_type',$this->bt_order_type,true);

		$criteria->compare('date_time',$this->date_time,true);

		$criteria->compare('dealer',$this->dealer,true);

		$criteria->compare('rate',$this->rate,true);

		$criteria->compare('broker',$this->broker,true);

		$criteria->compare('recapped',$this->recapped,true);

		$criteria->compare('settled',$this->settled,true);

		$criteria->compare('sett_date',$this->sett_date,true);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

Controller


public function actionIndex()

	{

		$model=new BrokerTrades('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['BrokerTrades']))

			$model->attributes=$_GET['BrokerTrades'];

		

		print_r($_GET)	;

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

			'model'=>$model,

		));

	}

I can not see why this filter is not work please help.

fisrt things first

your values should be like this


'value'=>'$data->attribute'

Thanks Reza it is displaying the data fine but still not filtering :mellow:

these lines in your search and index methods does nothing and are useless, Although they don’t affect main functionality.

search:




echo "booker ".$this->broker;// exit;

               //above only displays booker there is nothing in $this->broker



index:




print_r($_GET)  ;



by the way, I can’t see any problem in your codes ,so check your rules for start

Hi

I know these line do not do anything I was trying to work out if anything was getting passed back to the controller and model, and nothing was.

My rules are below


public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('bt_number, sign, fm_buys, fm_buys_amt, against, bt_sett_date, bt_order_type, date_time, dealer, rate, broker, sett_date', 'required'),

			array('bt_number', 'numerical', 'integerOnly'=>true),

			array('sign, recapped, settled', 'length', 'max'=>1),

			array('fm_buys, against', 'length', 'max'=>3),

			array('fm_buys_amt, rate', 'length', 'max'=>16),

			array('bt_order_type, dealer', 'length', 'max'=>20),

			array('broker', 'length', 'max'=>30),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('bt_number, sign, fm_buys, fm_buys_amt, against, bt_sett_date, bt_order_type, date_time, dealer, rate, broker, recapped, settled, sett_date', 'safe', 'on'=>'search'),

		);

	}



The above rules are the ones that where made with the model.

I fixed this, my dropdown value was wrong, thanks for your help.