yii - How do I apply a CDataColumn filter to my CGridView so it displays only rows with a null-value? -
i have model boolean value, generated table this:
create table receivable ( ... is_paid integer default null, ... ) you should take notice of possible null value.
i have gii-generated receivable.php-model , simple cgridview, this:
$dataprovider = $model->search(); $dataprovider->pagination = ['pagesize'=>20]; $this->widget('zii.widgets.grid.cgridview', array( 'dataprovider'=>$dataprovider, 'filter'=>$model, 'columns'=>array( 'id', [ 'name'=>'is_paid', 'type'=>'raw', 'value'=>'($data->is_paid==1)?"paid":"";', 'filter'=>['1'=>'paid', '0'=>'0'] ], 'someothercolumn', ['class'=>'cbuttoncolumn'] ), ); it should make sense far? work fine must say, 1 tiny problem - want allow filtering on null values well!
'filter'=>['1'=>'paid', '0'=>'0', null=>'null'] // shows records. 'filter'=>['1'=>'paid', '0'=>'0', ''=>'null'] // shows records. 'filter'=>['1'=>'paid', '<>1'=>'null or zero'] // shows 0-records only. well, i'm @ loss. there way can use cdatacolumn.filter allow user filter on null values? (only display rows 'is_paid'==null)
edit: values can 1,0 or null, filter can applied 1 or 0 (or show everything). how can let user display rows null-values only?
any appreciated!
this 1 way can
1.'filter' => array('0' => yii::t('app', 'no'), '1' => yii::t('app', 'yes')), or
2.is_paid:boolean or
3.'filter' => chtml::listdata(userregistry::model()->findall(), 'id_user_registry', 'firstname' ), in above example have values in db table
or
4.'filter' => lookup::items('option'), and above example in model have
4. public static function items($type, $code) { if(!isset(self::$_items[$type])) self::loaditems($type); return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false; } private static function loaditems($type) { self::$_items[$type]=array(); $models=self::model()->findall(array( 'condition'=>'type=:type', 'params'=>array(':type'=>$type), //'order'=>'position', )); foreach($models $model) self::$_items[$type][$model->code]=$model->name; }
Comments
Post a Comment