Yii Framework Forum: Zii Grid View Action Customization - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Zii Grid View Action Customization zii grid view action customization Rate Topic: -----

#1 User is offline   Alankar Singh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-March 12

Posted 20 March 2013 - 03:08 PM

Hello

I am using zii grid view, i change action buttons and they are working fine, using this link Click Here

But i have to add button customization in every controller, Is there any other way by that i can manage it via one file? means i dont want to add same code on every page.

Thanks in advance
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,327
  • Joined: 21-February 11
  • Location:Greece

Posted 20 March 2013 - 03:34 PM

Hi Alnakar

One of the way is to extend the zii

Yii::import('zii.widgets.grid.CGridView');

class MyGridView extends CGridView
{
//override the appropriate methods, may call the parent::theMethod()
}


and use ext.yourgridview.yourFilegridview instead of zii.widgets.grid.CGridView


Another way is to create a method in components/conroller.php with argument an array parameters (the parameters of CGridView) merge this array with your custom button and call by itself the CGridView
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   Alankar Singh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-March 12

Posted 20 March 2013 - 11:56 PM

View PostKonApaz, on 20 March 2013 - 03:34 PM, said:

Hi Alnakar

One of the way is to extend the zii

Yii::import('zii.widgets.grid.CGridView');

class MyGridView extends CGridView
{
//override the appropriate methods, may call the parent::theMethod()
}


and use ext.yourgridview.yourFilegridview instead of zii.widgets.grid.CGridView


Another way is to create a method in components/conroller.php with argument an array parameters (the parameters of CGridView) merge this array with your custom button and call by itself the CGridView



Thanks KonApaz

Can you provide me some example code.
0

#4 User is offline   Lal Zada 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 125
  • Joined: 06-November 12
  • Location:Lahore, Pakistan

Posted 21 March 2013 - 05:17 AM

for gridview you have to extend CButtonColumn in components
Yii::import('zii.widgets.grid.CButtonColumn');

class BButtonColumn extends CButtonColumn{
 public  function initDefaultButtons(){
    // make ur changes here 
  }
}


then use BButtonColumn in ur gridview instead of CButtonColumn
Is it fast? Is it secure? Is it professional? Is it right for my next project? Yes, it is

Linkedin Facebook Twitter Google+
0

#5 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,327
  • Joined: 21-February 11
  • Location:Greece

Posted 21 March 2013 - 04:33 PM

View PostAlankar Singh, on 20 March 2013 - 11:56 PM, said:

Thanks KonApaz

Can you provide me some example code.



forget the first way I said.

by the second way
In the components/controller just add this code

public function myGridview($arrParams) {

$default = array(
'columns'=>array(
array(
'class'=>'yourCButtonColumn',        
),
),
);

$finalArr = array_merge_recursive($arrParams,$default)
 $this->widget('zii.widgets.grid.CGridView', $finalArr);
}




Make the yourCButtonColumn as Lal Zada post

and in view file call the above function like

$this->myGridview(array( 
'id'=>'an_id',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
		'id',
		'text',
		'title',
		'and_so_on',
)
));



with this, you minimize the code by add only no-default attributes, I didn't checked the code so test by yourself and tell us if it works! :)
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#6 User is offline   Alankar Singh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-March 12

Posted 24 March 2013 - 02:15 PM

View PostKonApaz, on 21 March 2013 - 04:33 PM, said:

forget the first way I said.

by the second way
In the components/controller just add this code

public function myGridview($arrParams) {

$default = array(
'columns'=>array(
array(
'class'=>'yourCButtonColumn',        
),
),
);

$finalArr = array_merge_recursive($arrParams,$default)
 $this->widget('zii.widgets.grid.CGridView', $finalArr);
}




Make the yourCButtonColumn as Lal Zada post

and in view file call the above function like

$this->myGridview(array( 
'id'=>'an_id',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
		'id',
		'text',
		'title',
		'and_so_on',
)
));



with this, you minimize the code by add only no-default attributes, I didn't checked the code so test by yourself and tell us if it works! :)


Thanks
0

#7 User is offline   Alankar Singh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-March 12

Posted 25 March 2013 - 02:21 PM

View PostAlankar Singh, on 24 March 2013 - 02:15 PM, said:

Thanks

Hi Konapaz

http://www.yiiframew...__1#entry198465

Can you reply on this issue also.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users