This is my cgridview.Here view,update,delete works fine. but I want to impliment soft deletion . so how can i customize the delete button here?
<div id="status" style="display:none;margin-left:450px;margin-top:25px;"></div>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'printstatusforlocal-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'order_id',
'albumname',
'username',
'usermail',
'bookid',
array('header'=> 'No. of Pages',
'name'=>'noofpages',
'value'=>$model->noofpages,
),
array('header'=> 'Order Date',
'name'=>'orderdate',
'value'=>$model->orderdate,
),
array('header'=> 'Synchronized',
'name'=>'synchronize',
'value'=>'$data->Syncronize',
),
array(
'class'=>'CButtonColumn',
),),
));
?>
</div> <?php $this->endWidget(); ?>
Help me please..
You can create a separate action and set the url of the delete button using deleteButtonUrl:
...
array(
'class'=>'CButtonColumn',
'deleteButtonUrl' => 'array("controller/action", "id" => "$data->id")'
),),
Related
i'm having trouble retrieving data from the database where i have joined table user to table family_tree thrice. CdbCommand returns the values selected from the first table (family_tree) fine, but the data selected from the 2nd and 3rd table (user) are not returned.
the schema of the tables are:
user
user_id | user_fullname
family_tree
tree_creator_id | tree_user1_id | tree_user2_id
model/familytree.php:
public function search()
{
// #todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
//$criteria->alias='FamilyTree';
$criteria->select='t.*,A.*,B.*,C.*';
$criteria->join = 'join user A on A.user_id=tree_user1_id
join user B on B.user_id=tree_user2_id
join user C on C.user_id=tree_creator_id';
$criteria->compare('tree_id',$this->tree_id,true);
$criteria->compare('tree_creator_id',$this->tree_creator_id,true);
$criteria->compare('tree_user1_id',$this->tree_user1_id,true);
$criteria->compare('tree_user2_id',$this->tree_user2_id,true);
$criteria->compare('tree_type',$this->tree_type,true);
$criteria->compare('tree_type_name',$this->tree_type_name,true);
$criteria->compare('tree_grey_flag',$this->tree_grey_flag);
//$criteria->join('user', 'tree_creator_id=user.user_id');
//$criteria->compare('tree_user_id',$this->A->user_fullname, true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
view/familytree/admin.php
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'family-tree-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
'tree_id',
'tree_creator_id',
'C.user_fullname',
'tree_user1_id',
'A.user_fullname',
'tree_user2_id',
'B.user_fullname',
'tree_type',
'tree_type_name',
/*'tree_grey_flag',*/
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Please you can try this below code:
model/familytree.php
/**
* #return array relational rules.
*/
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'treeCreaterRel' => array(self::BELONGS_TO, 'user', 'tree_creator_id'),
'treeUser1Rel' => array(self::BELONGS_TO, 'user', 'tree_user1_id'),
'treeUser2Rel' => array(self::BELONGS_TO, 'user', 'tree_user2_id'),
);
}
public function search()
{
// #todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('treeCreaterRel', 'treeUser1Rel', 'treeUser2Rel');
$criteria->together = true;
$criteria->compare('tree_id',$this->tree_id,true);
$criteria->compare('tree_creator_id',$this->tree_creator_id,true);
$criteria->compare('tree_user1_id',$this->tree_user1_id,true);
$criteria->compare('tree_user2_id',$this->tree_user2_id,true);
$criteria->compare('tree_type',$this->tree_type,true);
$criteria->compare('tree_type_name',$this->tree_type_name,true);
$criteria->compare('tree_grey_flag',$this->tree_grey_flag);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>'10', //Yii::app()->params['defaultPageSize'],
//'currentPage'=>$currentPage
),
'sort'=>array(
'defaultOrder'=>array(
'tree_id'=>CSort::SORT_DESC
),
),
));
}
view/familytree/admin.php
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'family-tree-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'header' => 'Tree Id',
'name' => 'tree_id',
'value' => '$data->tree_id'
),
array(
'header' => 'Tree Creater Id',
'name' => 'tree_id',
'value' => '$data->tree_id'
),
array(
'header' => 'Tree Creater Name',
'name' => 'tree_creator_id',
'value' => '$data->treeCreaterRel->user_fullname'
),
array(
'header' => 'Tree User1 Name',
'name' => 'tree_user1_id',
'value' => '$data->treeUser1Rel->user_fullname'
),
array(
'header' => 'Tree User1 id',
'name' => 'tree_user1_id',
'value' => '$data->tree_user1_id'
),
array(
'header' => 'Tree User2 Name',
'name' => 'tree_user2_id',
'value' => '$data->treeUser2Rel->user_fullname'
),
array(
'header' => 'Tree User2 id',
'name' => 'tree_user2_id',
'value' => '$data->tree_user2_id'
),
'tree_type',
'tree_type_name',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
I have that code in my admin.php i.e. view file in my Yii Project.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'topic-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'name',
'description:html', // I want to change this
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Actually description:html is showing a lot of text description which is stored in my database.
So my question is that, I want to print just a single line of description here.
So I don't know how to accomplish it.
Any help will be appreciated.
Thanks.
Although hett has given an answer but you can do this also
array(
'name'=>'description',
'value'=>array($this,'showFewLines')
),
and then in your controller create a function
public function showFewLines($data,$row)
{
$allData=$data->description;
return substr($allData, 0, 40);
}
somehow
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'topic-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'name',
array(
'name'=>'description',
'value'=>function($data) {
return substr($data->description, 0, strpos($data->description, '<br>'));
},
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
I am trying to set the pageSize property of pager in CGridView but in vain. By the way currently there are total of 2 items, i want to display only 1 on 1 page. Thanks.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'pager' => array(
'pageSize' => 1,
),
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'username',
'email',
'pass',
'type',
'date_entered',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
remove the following from the view
'pager' => array(
'pageSize' => 1,
),
inside the dataprovider array in your model search method add this code
$dataProvider = new CActiveDataProvider('your_model', array(
'pagination'=>array(
'pageSize'=>your_page_size,
),
'criteria'=>$criteria,
));
How to Pop Up A New Windwon In Gridview?
When the use click the refund button of gridview, I would like to display the popup box with the data. How can I do?
This is the my gridview
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'advance-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array('name' => 'acc_category_id',
'value'=>'(isset($data->acccategories->name)) ? CHtml::encode($data->acccategories->status) :"Not Set"',
'filter'=>CHtml::listData($acccate, 'id', 'name'),
),
array('name' => 'accmain_id',
'value'=>'(isset($data->accmains->name)) ? CHtml::encode($data->accmains->name) :"Not Set"',
'filter'=>CHtml::listData($accmain, 'id', 'name'),
),
array('name' => 'job_id',
'value'=>'(isset($data->jobs->name)) ? CHtml::encode($data->jobs->name) :"Not Set"',
//'filter'=>CHtml::listData($job, 'id', 'name'),
),
'currency',
'amount',
array('name' => 'created_date',
'value'=>'Yii::app()->dateFormatter->format("d MMM y",strtotime($data->created_date))',
// 'filter'=>CHtml::listData($job, 'id', 'name'),
),
array(
'class'=>'CButtonColumn',
'template'=>'{update} {delete} {refund}',
'buttons'=>array
(
'update' => array
(
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/edit.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/update", array("id"=>$data->id))',
),
'delete' => array
(
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/delete.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/delete", array("id"=>$data->id))',
),
'refund' => array
(
'type'=>'raw',
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/icon_refund_loans2.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/view", array("id"=>$data->id))',
),
),
),
),
'htmlOptions' => array(
//'class' => 'table table-bordered table-striped table_vam grid_widget',
),
)); ?>
<div id="loadingdiv" style="float:right; margin-right:160px;"> </div>
<div id="jobslist"></div>
=====================================
update
when I update the grid by following and check by firebug, it is displaying the data at firebug. but not display popup.
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::ajaxLink($data->id, array("advance/jobslist", "id"=>$data->id), array("onclick"=>\'$("#jobslist").dialog("open"); return false;\'));',
),
This is controller
public function actionJobslist()
{
$model=new Job('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Customer']))
$model->attributes=$_GET['Customer'];
if(isset($_GET['AccRecei']))
$accrecei->attributes=$_GET['AccRecei'];
$this->renderPartial('jobs_listing',array('model'=>$model),false,true);
}
this is view/jobs_listing.php
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'jobslist',
'options'=>array(
'title'=>Yii::t('job','Jobs List'),
'autoOpen'=>true,
'modal'=>'true',
'width'=>'750',
'height'=>'500',
),
));
echo $this->renderPartial('_jobs_listing', array('model'=>$model)); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
how should I do?
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::link($data->id, array("id"=>$data->id, 'class'=>'view-popup'));',
),
and insert javascript:
$('.view-popup').live('click', function() {
var id = $(this).attr('id');
window.open("<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/your_path/id/'; ?>" + id,'popUpWindow','height=800,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
return false;
});
Inner of the grid
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::ajaxLink($data->id, array("advance/jobslist", "id"=>$data->id), array(
"onclick"=>"$(\"#jobslist\").dialog(\"open\"); return false;","update"=>"#jobslist",
"beforeSend" => "function() {
$(\"#loadingdiv\").addClass(\"ajaxloading\");
}",
"complete" => "function() {
$(\"#loadingdiv\").removeClass(\"ajaxloading\");
}",
),array("id"=>"showcustomerlist2"));',
),
Out of the grid
<div id="loadingdiv" style="float:right; margin-right:160px;"> </div>
<div id="jobslist2"></div>
I have a CGridView as follows,
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'order-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'order_id',
//'ordered_datetime',
'customer_id',
'status',
//'delivery_address',
array(
'class'=>'CButtonColumn',
'template' => '{view} {rollback} {receive}{pack} {dispatch}{delivered}',
'htmlOptions'=>array('width'=>'250px'),
'buttons'=>array(
'receive'=>array(
'id'=>'receive',
'name'=>'receive',
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&received=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'type'=>'submit',
'imageUrl'=>'/mdg/images/Receive1.png',
'visible'=>'($data->status=="pending")?true:false;'
),
'rollback'=>array(
'id'=>'rollback',
'name'=>'rollback',
'click'=>''
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&rollback=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'imageUrl'=>'/mdg/images/rollback.jpg',
'visible'=>'($data->status=="pending")?false:true;'
),
),
),
),
)); ?>
And When I add one more button to the buttons array, the filter doesn't work. Any Idea why that is?
There is an extra click => '', in the recieve button's array.