BWSnippet

Yii Tips using Booster & TbGridView

Yii Tips using Booster & TbGridView

Yii Booster Tips and tricks with TbGridView

Yii using Booster

TbGridView Stuff

Yii Booster using TbGridView with related data , adding proper links to options, and adding htmlOptions

TbGridView with dynamic data

 

 

array(

	'name' => 'company_id',

	'value' => 'Company::Model()->FindByPk($data->company_id)->name',

	), 

 

 

adding filter

 

 

array(

	'name' => 'company_id',

	'filter' => CHtml::listData(Company::model()->findAll(), 'id', 'name'),

	'value' => 'Company::Model()->FindByPk($data->company_id)->name',

	), 

 

 

adding proper links for editing

 

 

array(

	'htmlOptions' => array('nowrap'=>'nowrap'),

	'class'=>'bootstrap.widgets.TbButtonColumn',

	'viewButtonUrl'=>'Yii::app()->createUrl("/expense/view", array("id"=>$data["id"]))',

	'updateButtonUrl'=>'Yii::app()->createUrl("/expense/update", array("id"=>$data["id"]))',

	'deleteButtonUrl'=>'Yii::app()->createUrl("/expense/delete", array("id"=>$data["id"]))',

	)

 

 

adding htmlOptions

 

 

array('name'=>'id', 'header'=>'#', 'htmlOptions'=>array('style'=>'width: 60px')),

 

 

So.. full example

 

 

$gridColumns = array(

	array('name'=>'id', 'header'=>'#', 'htmlOptions'=>array('style'=>'width: 60px')),

	array('name'=>'name', 'header'=>'name'),

	array(

	'name' => 'company_id',

	'filter' => CHtml::listData(Company::model()->findAll(), 'id', 'name'),

	'value' => 'Company::Model()->FindByPk($data->company_id)->name',

	),

	array(

	'htmlOptions' => array('nowrap'=>'nowrap'),

	'class'=>'bootstrap.widgets.TbButtonColumn',

	'viewButtonUrl'=>'Yii::app()->createUrl("/expense/view", array("id"=>$data["id"]))',

	'updateButtonUrl'=>'Yii::app()->createUrl("/expense/update", array("id"=>$data["id"]))',

	'deleteButtonUrl'=>'Yii::app()->createUrl("/expense/delete", array("id"=>$data["id"]))',

	)

	);

 

 

Add pagination to basic Grid View

 

$this->widget('bootstrap.widgets.TbGridView', array( 'dataProvider'=>$dataProvider, //'dataProvider'=>$model->search(), //'filter'=>$model, //'template'=>"{items}", 'template'=>"{items}\n{pager}", 'columns'=>$gridColumns, )); 

 

Tags

Yii Tips using Booster & TbGridView