Help: How to hide some data value in CGridView?

Dear all,

how could we hidden some data value in CGridview(hide column),




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

	'id'=>'t-user-grid',

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

	'filter'=>$model,

	'columns'=>array(

		array(

			'name'=>'name',

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

		),

		array(

			'name'=>'email',

			'value'=>'$data->email',   [b]//i want to hide this[/b] 

		),

		array(

			'class'=>'CButtonColumn',

		),

	),

));



Yes, i want to hide email value depending on login guest or admin.

Where i set this : Yii::app()->user->isGuest?

is there any best solutions or just add css style->display:none?

thanks for the time.

With display:none the data is not visible on screen but anybody can see it from “view source” so it’s not a good solution if the data is sensitive

I used something like




$columns[]=array(

   'name'=>'name',

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

);

if(!Yii::app()->user->isGuest) {

   $columns[]=array(

      'name'=>'email',

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

   );

}

$columns[]=array(

   'class'=>'CButtonColumn',

);


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

        'id'=>'t-user-grid',

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

        'filter'=>$model,

        'columns'=>$columns,

));



yess! that it is,

shame on me, dont realized its before. :angry:

with this approach we can manipulate value in CGridView too, such if value is an array(multi array) or such concait variable.

thanks mdomba, you are genius :lol:

btw mdomba, how can we set limit data in this CGridView?

in admin controller its confuse with search funtion




		$model=new t_user('search');



i know something like this, but its throw error?




		$dataProvider=new CActiveDataProvider('t_user', array(

			'pagination'=>array(

				'pageSize'=>self::PAGE_SIZE,

			),

		));



thank you.

What error you get?

If it’s about PAGE_SIZE maybe you have it in the controller (Yii version before 1.1.1), now you need to define it in the model because it’s here that it’s used…

Sorry for the wait(my proxy reset) :)

this error :




CException

Description


Property "CActiveDataProvider.ID_User" is not defined.



i try this code too.




	public function actionAdmin()

	{

		//$model=new t_user('search');  //previous model


		$model=new CActiveDataProvider('t_user', array(

			'pagination'=>array(

					'pageSize'=>'20',  // try this to :'pageSize'=>20

			),

		));

		

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

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


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

			'model'=>$model,

		));

	}



is there any related to seachy ajax funtion? a 'm using yii 1.1.2

thank.

in the controler leave the model as it was




       public function actionAdmin()

       {

                $model=new t_user('search');  //previous model


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

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


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

                        'model'=>$model,

                ));

       }

in the model function search return the CActiveDataProvider as:




    const PAGE_SIZE=50;


    public function search()

    {

        $criteria=new CDbCriteria;

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

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


        return new CActiveDataProvider('Osiguranja', array(

            'criteria'=>$criteria,

            'sort'=>array(

                'defaultOrder'=>'...',

            ),

            'pagination'=>array(

                'pageSize'=>self::PAGE_SIZE,

            ),

        ));

    }



in the view created by yiic 1.1.2 you have




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

    'id'=>'model-grid',

    'dataProvider'=>$model->search(),           // <-- $model->search() returns CActiveDataProvider

    'filter'=>$model,

    'columns'=>...,

));



its work great.!

big thanks for you mdomba. :lol:

i guess my mvc understanding still lack. :-X

btw, why my ckeditor in second page not loaded?

the same when i interact with seacrh ajax.

actually i hard code this html to CGridView value, and call it with divpopup id:




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

        'id'=>'t-user-grid',

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

        'filter'=>$model,

        'columns'=>array(

/*......*/

		array(

			'name'=>'Desk',

			'filter'=>false,

			'header'=>'',

			'type'=>'raw',

			'value'=>'"

<div id=\"popupdate$data->ID_User\" class=\"popupAll \">

		<form id=\"t-user-form_$data->ID_User\" action=\"\" method=\"post\"> 

		<textarea name=\"t_user[Desk]\" id=\"t_user_desk_$data->ID_User\">

		$data->Desk

		</textarea>

		</form>

</div>

<a href=\"#\" onclick=\"Popup.show(\'popupdate$data->ID_User\');return false;\">Update</a>

<script type=\"text/javascript\">

/*<![CDATA[*/

CKEDITOR.replace(\"t_user_desk_".$data->ID_User."\", 

{

	width: 520,

	height: 200,

	toolbar: \"Basic\"

});

CKFinder.SetupCKEditor(null, \"'.Yii::app()->getBaseUrl().'/assets/2bdf0eb8/ckfinder/\");

/*//]]>*/

		"'),

/*.......*/

	)

));



i am very sorry for this bad code practice mdomba, leave it as is this time, i will try juidialog again letter. ;)

btw what’s wrong with this ajax/ckeditor? ;D

i try call ckeditor with class=‘ckeditor’, not work too.

thanks.

First of all we are here on the third problem right now… it’s not a best practice to ask different question in the same thread…

for different problem - open a new thread - so that later someone with same/similar problem can find that thread and read the solutions :)

I haven’t used yet CKeditor and haven’t used the gridview with similar ajax functionality so someone else would maybe answer that, but would be better to open a new thread for that question…

Yet… seem strange to me that CKFinder.SetupCKEditor() is called for every row…

ha ha haa. ;D the spam code indeed.

i am very sorry for this bad habit of me.

btw thanks a lots for all your guide, sorry for bothering you this late.

:)

Not a problem at all…

btw… its morning on my timezone (CET) ;)