Following is my code.
<script type="text/javascript">
//jQuery(document).ready(function($) {
//jQuery('select[name="Vendor"]').on('change', function(){
jQuery('select[name="Vendor"]').change(function(){
var selectedValue = $(this).val();
alert("Selected Text: " + selectedValue);
if(this.value ==2){
jQuery('.grid_data').show();
}else{
jQuery('.grid_data_rel').show();
}
});
//});
</script>
When i change select value event only occur for one time not alert showing on second time.
Html is coming from yii grid view like
'filter'=>array('1'=>"Recomonded",'2'=>"Related"), this is html in code and i used in yii frame work.
so here i can not see my static html code it's coming from gridview in yii.
<?php
$sql = "SELECT product_id,product_name FROM `user_master` as u
INNER JOIN product_detail as p
ON p.vendor_id = u.u_id WHERE p.vendor_id =2";
$result = Yii::app()->db->createCommand($sql)->queryAll();
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-master-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'u_id',
// 'product_id',
// 'ut_id',
// 'country_id',
'fullname',
// 'ur.role_name',
array(
'header' => 'Role Name',
'name' => 'ur_id',
'value' => '$data->ur->role_name',
),
array(
'header' => 'Product Name',
'name' => 'product_id',
'value' => '$data->product_detail->product_name',
),
array(
'header' => 'Qty',
'name' => 'product_id',
'value' => '$data->product_detail->quantity',
),
array(
'header' => 'product_id',
'name' => 'product_id',
'value' => '$data->product_detail->product_id',
),
// 'representative_name',
'email',
// 'password',
'mobile',
array(
'header' => 'Image',
'name' => 'u_id',
'id'=>'u_id',
'type' => 'raw',
'filter'=>array('1'=>"Recomonded",'2'=>"Related"),
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
It's likely that the gridview is loading new html using ajax.
If that's the case, then your event listeners won't be attached to the new replacement select elements.
Why not use the commented out .on() method?
Move back to delegated events:
<script type="text/javascript">
jQuery(document).on('change', 'select[name="Vendor"]', function(){
if(this.value ==2){
jQuery('.grid_data').show();
}else{
jQuery('.grid_data_rel').show();
}
});
Related
Hello Friends this is my code
$this->widgets('ext.select.ESelect2', array(
'model' => $model,
'attribute' => 'state',
'data' => $data,
'htmloptions'=>array(
'multiple'=>'multiple',
),
'options' =>array(
'placeholder' => 'Select a state ...',
'allowClear'=> true,
),
));
How can i get option value and text in jquery. I want to need the value of selected options.
Please suggest and help me.
You can get the value of an input using their class or id of the input try this one:
$('#id_select_input').change(function() {
var selected = $(this).val();
var textValue = $this.text();
});
Hope this will help you.
$this->widgets('ext.select.ESelect2', array(
'id'=>'id_select_input',
'model' => $model,
'attribute' => 'state',
'data' => $data,
'htmloptions'=>array(
'multiple'=>'multiple',
),
'options' =>array(
'placeholder' => 'Select a state ...',
'allowClear'=> true,
),
));
I print some data using foreign key, but I don't how it was converted to array in my view page.
echo ucfirst(User::model()->findByPk($model->postby_id)->username);
$this->widget('bootstrap.widgets.TbDetailView', array(
'data' => $model,
'attributes' => array(`enter code here`
'id',
'title',
'question',
'detail',
//'postby_id',
array(
'name' => 'Post By',
'value' => ucfirst(User::model()->findByPk($model->postby_id)->username),
),
'verified',
'verifiedby_id',
'post_date',
'hits',
'status',
),
));
Try this:
array(
'name' => 'Post By',
'value' => echo ucfirst(User::model()->findByPk($model->postby_id)->username),
),
Or:
array(
'name' => 'Post By',
'value' => function(){
echo ucfirst(User::model()->findByPk($model->postby_id)->username)
},
),
Update:
From documentation, "value" can also be an anonymous function whose return value will be used as a value. The signature of the function should be function($data) where data refers to the data property of the detail view widget.. I think below solution can help you:
First define a function in your model:
public function getUsername($postby_id)
{
return ucfirst(User::model()->findByPk($postby_id)->username);
}
Then you can have this in your view:
array(
'name' => 'Post By',
'value' =>$model->getUsername($model->postby_id)),
),
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.
What I'm trying to accomplish with the following code is when the 'roleSelector' dropdown is changed, it fires a ajax request to the 'admin/permissions/assign' url which in turn, sets a state for the role selected. I need it as a state so I can use it in the CLinkColumn column within the CGridView. However, when the success javascript fires and the grid view reloads the content of the cgridview does not update, while the summary does (it shows the number of results that should be in the grid view).
I'm not sure why either but this seems to be the only CGridView that I've had to use the 'ajaxUrl' property in order for the $.fn.yiiGridView.update() call to work. If I omit the url property it returns an error stating it could not find the url which I don't recall having to set in the past.
The Action:
class AssignAction extends CAction {
// Used in the url to determine if we are assigning or revoking permissions
const FLAG_APPLY = 'apply';
const FLAG_REVOKE = 'revoke';
// Identifier to the user saved state of the role selected
const STATE_ROLE = 'roleSelected';
public function run($name='', $action='') {
// Get the role the user selected
if (isset($_POST['roleSelector'])) {
$roleSelected = $_POST['roleSelector'];
Yii::app()->user->setState(self::STATE_ROLE, $roleSelected);
Yii::app()->end();
}
// Get all of the roles from the system
$roleSelected = Yii::app()->user->getState(self::STATE_ROLE);
$roles = AuthItem::model()->byTypes(array(CAuthItem::TYPE_ROLE))->findAll();
$authItemProvider = new CActiveDataProvider('AuthItem', array(
'criteria' => array(
'condition' => (!$roleSelected) ? '1=0' : '',
),
'pagination' => array(
'pageSize' => 30,
)
));
$this->getController()->render('assign', array(
'roles' => $roles,
'roleSelected' => $roleSelected,
'authItemProvider' => $authItemProvider,
));
}
}
The View:
<div id="content-header">
<h1 class="p-mt10">Assign Permissions</h1>
<div class="p-fr p-pb10">
<?php
$roleList = CHtml::listData($roles, 'name', 'label');
echo CHtml::dropDownList('roleSelector', $roleSelected, $roleList, $htmlOptions=array(
'empty' => 'Select a Role',
'ajax' => array(
'type' => 'POST',
'url' => $this->createUrl('/admin/permissions/assign'),
'data' => array('roleSelector' => 'js: $(this).val()'),
'success' => 'js: function() { $.fn.yiiGridView.update("GridView-AuthItem") }',
),
));
?>
</div>
</div>
<div id="content-body">
<table>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'GridView-AuthItem',
'dataProvider' => $authItemProvider,
'columns' => array(
'label:properCase',
'typeName:properCase',
'description',
'bizrule',
array(
'class' => 'CLinkColumn',
'label' => 'Assign',
'urlExpression' => 'array("/admin/permissions/assign",
"name" => $data->name,
"action" => (AuthItemChild::model()->byParentAndChild(Yii::app()->user->getState(AssignAction::STATE_ROLE), $data->name)->find()
? AssignAction::FLAG_REVOKE : AssignAction::FLAG_APPLY),
)',
'htmlOptions' => array(
'style' => 'text-align: center',
),
'linkHtmlOptions' => array(
'class' => 'button gray icon i_stm_edit',
),
),
),
));
?>
</table>
</div>
I forgot I left the table tags in there since it originally was a CListView. Removing those tags seems to have fixed my problem.
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>