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>
Related
I want to show the date that the user picked from the date picker inside the field of the search after searching and submitting by Ajax.
I used this
'afterAjaxUpdate' => 'reinstallDatePicker',
and
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
$('#created_at').datepicker();
}
");
You can try this way
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'test-master-grid',
'dataProvider'=>$dataProvider,
'afterAjaxUpdate' => 'reInstallDatepicker',
'filter'=>$model,
'columns'=>array(
array(
array(
'name'=>'event_master_end_date',
'type'=>'raw',
'value'=>'($data->date == 0000-00-00) ? "Not Set" : date_format(new DateTime($data->date), "d-m-Y")',
'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'date',
'options'=>array(
'dateFormat'=>'dd-mm-yy',
'changeYear'=>'true',
'changeMonth'=>'true',
'showAnim' =>'slide',
),
'htmlOptions'=>array(
'id'=>'date',
),
),
true),
),
),
));
Yii::app()->clientScript->registerScript('for-date-picker',"
function reInstallDatepicker(id, data){
$('#date').datepicker({'dateFormat':'dd-mm-yy'});
}
");
?>
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 am displaying form elements in my CGridView and would like datepicker, but it complains
CDataColumn and its behaviors do not have a method or closure named "widget".
I have modified DATEIN using the method described in Use a widget in a statically-called method However i think it works partially as when i do a sort or the datepicker does not work. its working only on initial load.
<script>
$(document).ready(function() {
/*
$("input[name*='DATEIN'] ").each(function(){
jQuery(this).datepicker({'dateFormat':'<?=Yii::app()->params["localdate"]; ?>'});
});
*/
$("input[name*='datedone'] ").each(function(){
jQuery(this).datepicker({'dateFormat':'<?=Yii::app()->params["localdate"]; ?>'});
});
});
</script>
<?php
$job = new Jobs();
$buttonPlus = CHtml::ajaxLink('Add New Line', $this->createUrl('addNewLine',array("id"=>$model->id)), array(
'type' => 'POST',
'data' => array('id' => $model->id),
'success' => 'function(html){ $.fn.yiiGridView.update("jobs-grid"); $.fn.yiiGridView.update("detailsseismic-grid"); $.fn.yiiGridView.update("details3d-grid"); }'
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'jobs-grid',
'dataProvider'=>$job->searchbyproject($model->PROJID),
'afterAjaxUpdate'=>'function(id,options){
$("#jobs-grid").children("table").children("thead").children("tr").children("th").children("a").each(function(){
$(this).click(function(){
var x = getQueryParams(this.href);
if($("#detailsgeoscan-grid").length)
$.fn.yiiGridView.update("detailsgeoscan-grid",{data:"sort="+x.sort});
else if($("#detailsseismic-grid").length)
$.fn.yiiGridView.update("detailsseismic-grid",{data:"sort="+x.sort});
else if($("#details3d-grid").length)
$.fn.yiiGridView.update("details3d-grid",{data:"sort="+x.sort});
});
});
$("#jobs-grid").children("div").children("ul").children("li").children("a").each(function(){
$(this).click(function(){
var x = getQueryParams(this.href);
if($("#detailsgeoscan-grid").length)
$.fn.yiiGridView.update("detailsgeoscan-grid",{data:"Detailsgeoscan_page="+x.Jobs_page});
else if($("#detailsseismic-grid").length)
$.fn.yiiGridView.update("detailsseismic-grid",{data:"Detailsseismic_page="+x.Jobs_page});
else if($("#details3d-grid").length)
$.fn.yiiGridView.update("details3d-grid",{data:"Details3d_page="+x.Jobs_page});
});
});
/*
$("input[name*=\'DATEIN\'] ").each(function(){
jQuery(this).datepicker({"dateFormat":"'. Yii::app()->params["localdate"]. '"});
});
*/
$("input[name*=\'datedone\'] ").each(function(){
jQuery(this).datepicker({"dateFormat":"'. Yii::app()->params["localdate"].'"});
});
}',
'summaryText' => '',
'columns'=>array(
array(
'name'=>'JOBNO',
'value'=>'CHtml::activeHiddenField($data, "[$row]JOBNO")' ,
'type'=>'raw',
'headerHtmlOptions' => array('style' => 'display:none;'),
'htmlOptions' => array('style' => 'display:none'),
'footer' => $buttonPlus,
'footerHtmlOptions'=> array('colspan' => '7'),
),
array(
'name'=>'NAME',
'value'=>'CHtml::activeTextField($data, "[$row]NAME", array("size"=>25))' ,
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'name'=>'SEQ',
'value'=>'CHtml::activeTextField($data, "[$row]SEQ", array("size"=>15))' ,
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'name'=>'DATEIN',
//'value'=>'CHtml::activeTextField($data, "[$row]DATEIN", array("size"=>10))' ,
'value' => function ($data, $row, $column) {
$controller = $column->grid->owner;
echo $controller->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$data,
'attribute'=>'DATEIN',
// additional javascript options for the date picker plugin
'htmlOptions'=>array(
'class'=>'datefield',
'id' => 'Jobs_'.$row.'_DATEIN',
),
'options' => array(
'dateFormat' => Yii::app()->params["localdate"],
)
),true);
},
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'header'=>"Process Complete <div id='checkboxgroup'> $processcompleteheader </div>",
'value'=>'$data->getcheckboxProcesses($row)',
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'name'=>'DATEDONE',
'value'=>'CHtml::activeTextField((count($data->jobsprocesscomplete)>0) ? $data->jobsprocesscomplete(array("order"=>"datedone desc")) : new Jobsprocesscomplete , "[$row]datedone", array("size"=>10))' ,
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
'sortable' => false,
),
array(
'name'=>'COMMENTS',
'value'=>'CHtml::activeTextField($data, "[$row]COMMENTS", array("style"=>"width:150px"))' ,
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'header'=>'<a id="deletealljobs" title="Delete All Lines" onclick="deleteAllJob(\'1409099\')" href="#">X</a>',
'class'=>'CButtonColumn',
'template'=>'{delete}',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
),
));
?>
I render it on from another view
$processcompleteheader = null;
foreach ($processstages as $k => $v) {
$processcompleteheader .= CHtml::Checkbox($k."_all",'',array("value"=>$k,"title"=>$v));
}
$lineListContent = "<div id='form_line_list'>
<div style='display: block;
left: 565px;
position: absolute;
top: 7px;'> " .CHtml::hiddenField("PROJID",$model->PROJID) . CHtml::hiddenField("id",$model->id) . CHtml::activeFileField(new Fileupload,'jobs', array('onChange'=>'showLoadDialog();submit(this)'))."<a id=clearfile href=# onclick='clearfile()' />X</a></div>";
$lineListContent .= $this->renderPartial("/jobs/_formJobsGridview",array("model"=>$model,"processcompleteheader"=>$processcompleteheader),true);
$lineListContent .= "</div>";
I think this question over here can help you out:
Use a widget in a statically-called method
Basically this widget can be called by the controller, but in your code you are trying to call it by the gridview.
I cant list data in grid using yii framework.My controller is Sitecontroller.php,My view is list_jobseeker.php .I got the error "Fatal error: Call to a member function getData() on a non-object ".Anybody help me?
My controller code
public function actionlist_jobseeker()
{
$session_id=Yii::app()->session['user_id'];
if ($session_id == "")
{
$this->redirect( array('/employee/site/login'));
}
$user_id =$session_id;
$models = Yii::app()->db->createCommand()
->select('*')
->from('job_seeker_profile s')
->join('job_profile j','s.user_id = j.user_id')
->order('s.id')
->queryAll();
$this->render('list_jobseeker',array('models' =>$models));
}
View- list_jobseeker.php
<h1>View Jobseeker</h1>
<div class="flash-success">
</div>
<div class="form">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'rates-phase-grid',
'htmlOptions' => array('class' => 'table table-striped table-bordered table-hover'),
'dataProvider'=>new CArrayDataProvider($models),
'columns' => array(
array(
'name' => 'Name',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->name)',
'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz'),
),
array(
'name' => 'Email',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->email)',
'htmlOptions' => array('style'=>'width:250px;','class'=>'zzz')
),
array(
'name' => 'Password',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->password)',
'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz')
),
array(
'name' => 'Contact No',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->contact_no)',
'htmlOptions' => array('style'=>'width:40px;','class'=>'zzz')
),
array(
'name' => 'Gender',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->gender)',
'htmlOptions' => array('style'=>'width:40px;','class'=>'zzz')
),
array(
'class' =>'CButtonColumn',
'deleteConfirmation'=>'Are you sure you want to delte this item?',
'template'=>'{update}{delete}',
'buttons' =>array('update'=>array(
'label'=>'edit',
'url'=>'Yii::app()->controller->createUrl("UpdateJob",array("id"=>$data["id"]))',
),
'delete'=>array('label'=>'delete',
'url'=>'Yii::app()->controller->createUrl("DeleteJob",array("id"=>$data["id"]))'),
)
)
),
));
?>
dataProvider should be a CDataProvider instance. You are passing in an array: $model. You could wrap this in a CArrayDataProvider:
'dataProvider' => new CArrayDataProvider($model),
A couple of other issues:
a) Your gridview expects $data to be an object and not an array. Either alter all $data->* instances to $data[*] or use CActiveDataProvider and the CActiveRecord instance for the job_seeker_profile table
b) By convention $model usually refers to a single CModel instance. Your array should therefore be named something else in plural e.g $items
I use this:
$data = ...::model()->findAll();
$dataProvider=new CArrayDataProvider('Class of your object');
$dataProvider->setData($data);
$dataProvider->keyField = "primary key of your model";
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
...
array( 'class'=>'CButtonColumn',
'template' => '{ver}',
'buttons' => array(
'ver' => array(
'url'=>'"?id=".$data["..."]',
'imageUrl'=> Yii::app()->baseUrl.'/images/view.png', //Image URL of the button.
),
)
),
I'm using TbButtonColumn to render some icon buttons. I want to render text instead of the icons. Is this possible and how would I alter the following code to do this?
$gridColumns = array(
array('name'=>'nick_name', 'header'=>'Interests Sets'),
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{add} {view}',
'buttons'=>array(
'add' => array
(
'label'=>'See this friend\'s list',
'icon'=>'plus',
'url'=>'Yii::app()->createUrl("itemList/viewlist", array("friend_id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
'view' => array(
'label'=>'Search under this friend\'s interesrs',
'url'=>'Yii::app()->createUrl("friend/filter", array("friend_id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
),
)
);
I know nothing about yii-booster, but if it's anything like Yii's CButtonColumn, you only need to set the imageUrl to false. Like this:
'view' => array(
'imageUrl'=>false, // Setting an empty string does not work in vanilla Yii.
'label'=>'Search under this friend\'s interesrs',
'url'=>'Yii::app()->createUrl("friend/filter", array("friend_id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
$gridColumns = array(
...
'buttons'=>array(
'add' => array
(
'label'=>'text instead of the icons' . 'See this friend\'s list',
'url'=>'Yii::app()->createUrl("itemList/viewlist", array("friend_id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
),
)
);
if you set 'icon'=>'ololo', run this code:
if (isset($this->icon))
{
if (strpos($this->icon, 'icon') === false)
$this->icon = 'icon-'.implode(' icon-', explode(' ', $this->icon));
$this->label = '<i class="'.$this->icon.'"></i> '.$this->label;
}