CJUIDatePicker with CGridView doesn't work - php

I am trying to include a Datepicker inside the CGridView as follows, the datepicker widget is used within the Grid View.
this->widget('zii.widgets.grid.CGridView', array(
'id'=>'order-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'order_id',
'customer.address.firstname',
'customer.address.lastname',
/*array('name' => 'ordering_date',
'value' => 'date("M j, Y", $data->ordering_date)'),
*/
array('name'=>'ordering_date',
'value'=>'$data->ordering_date',
'filter'=>$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'ordering_date',
'options'=>array(
'showButtonPanel'=>true,
'changeYear'=>true,
)
),
true),
'htmlOptions'=>array('width'=>'80','style'=>'text-align:center'),
),
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;'
),
'pack'=>array(
'id'=>'pack',
'name'=>'pack',
'type'=>'submit',
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&packed=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'click'=>'',
'imageUrl'=>'/mdg/images/pack1.png',
'visible'=>'($data->status=="received")?true:false;'
),
'dispatch'=>array(
'id'=>'dispatch',
'name'=>'dispatch',
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&dispatched=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'click'=>'',
'imageUrl'=>'/mdg/images/dispatch.png',
'visible'=>'($data->status=="packed")?true:false;'
),
'delivered'=>array(
'id'=>'delivered',
'name'=>'delivered',
'url'=>'',
'click'=>'',
'imageUrl'=>'/mdg/images/delivered1.png',
'visible'=>'($data->status=="dispatched")?true:false;'
),
'rollback'=>array(
'id'=>'rollback',
'name'=>'rollback',
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&rollback=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'click'=>'',
'imageUrl'=>'/mdg/images/rollback.jpg',
'visible'=>'($data->status=="pending")?false:true;'
),
),
),
'status',
),
'afterAjaxUpdate'=>'function(){
jQuery("#'.CHtml::activeId($model, 'ordering_date').'").datepicker({showButtonPanel:true, changeYear:true});
}',
)); ?>
This Code was taken from a suggestion given in the yiiframework forum. But it doesnt do anything.
Any idea why that is?
Thanks!

In this case I would put the date picker in the _search view. If you used Gii to generate your CRUD, it should already be there, available from the admin view:
<?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 -->

Related

PHP two modules exclude eachother

On my site I have panel control and some content. Site is build on Yii framework.
panel menu:
<?php
$this->breadcrumbs=array(
'Muzyka media'=>array('admin'),
'Lista',
);
$this->renderPartial('_submenu',array('model'=>$model));
?>
and content:
<?php
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'muzyka-media-grid',
'type'=>'stripped bordered condensed',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'name',
array(
'name'=>'mime_type',
'value'=>array($this,'displayMediaContent'),
'type'=>'raw',
'htmlOptions'=>array('class'=>'span3'),
'filter'=>CHtml::listData(MuzykaMedia::model()->findAll(),'mime_type','mime_type'),
),
'file_extension',
array(
'name'=>'file_size',
'filter'=>false
),
'count_views',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
));
?>
Both parts work separately but for some reason I can't see, when put one after another the sub-menu doesn't render.
Your code is definitely Yii1.1. If you're rendering partial views from inside another view, as you seem to be doing here, then you need to echo the result, so your code should look like this;
<?php
$this->breadcrumbs=array(
'Muzyka media'=>array('admin'),
'Lista',
);
echo $this->renderPartial('_submenu',array('model'=>$model));
?>

Yii Sort By Clistview not working

I'm using Yii 1.1.15. I got to my CListView to populate the table correctly on page load. but when i try to sort the table by store name the ajax response is the html for the whole page. and the table is empty.
but when i refresh the page &sort=store or &sort=store.desc the page works fine and sorts proper too. Any ideas what i'm doing wrong?
In my Controller
$dataProvider=new CActiveDataProvider('Store',
array(
'criteria' => array(
'condition'=>$_search_conditions,
'params'=>$search_params,
),
'sort'=>array(
'defaultOrder'=>'store DESC',
'attributes'=>array(
'store'=>array(
'asc'=>'store',
'desc'=>'store DESC',
),
'*',
)
),
)
);
$model = new Store;
$model->unsetAttributes(); // clear any default values
//render page
$this->render('index',array(
'dataProvider'=>$dataProvider,
'model'=>$model
));
In my View
$this->widget('zii.widgets.CListView', array(
'id' => 'store-list',
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'enableHistory'=> true,
'pagerCssClass' => 'pagination',
'ajaxUpdate'=>'store-list',
'loadingCssClass' => '', //remove loading icon
'sortableAttributes'=>array(
'store',
//'state' => 'State',
//'distance' => 'Distance'
),
'emptyText' => '<div class="alert alert-info">No data found</div>',
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left visible-lg visible-md visible-sm">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>
<div class="row">
<div class="col-md-12">
{pager}
</div>
</div>',
'pager' => array('id'=>'_pagination',
'class' => 'LinkPager',
'header' => '', //remove pagination header
'htmlOptions'=>array('class'=>'pagination') //add bootstrap pagination class
),
));
also in my function parseUrl() i have this code which does echo the correct value for $_GET['Store_sort'] the code below is used in my custom url manager class
if (!empty($_GET['sort']))
{
echo $_GET['Store_sort'] = $_GET['sort'];
}
UPDATE: even with friendly url disabled it does not sort. here is the URL of the ajax post. The pagination doesnt work either
http://localhost/dev/frontend/www/store/store/index/?Store_sort=store.desc&ajax=store-list

yii tbgridview. showing only paritcular row data

I have a inventory table. Now, using this table, I want to show the data on Pharmacy module in a Tbgridview such that it only displays those inventories from the Pharmacy store. i.e. row with category_id=2.
How, can I do this on the drug's index page. This is the code for index page of Pharmacy.
<?php
$this->menu=array(
array('label'=>'Add Drug', 'icon'=>'icon-plus', 'url'=>Yii::app()->controller->createUrl('create'), 'linkOptions'=>array()),
array('label'=>'List Drugs', 'icon'=>'icon-th-list', 'url'=>Yii::app()->controller->createUrl('index'),'active'=>true, 'linkOptions'=>array()),
array('label'=>'List Orders', 'icon'=>'icon-th-list', 'url'=>Yii::app()->controller->createUrl('PhOrder/index'), 'linkOptions'=>array()),
array('label'=>'List Distributors', 'icon'=>'icon-th-list', 'url'=>Yii::app()->controller->createUrl('PhDistributor/index'), 'linkOptions'=>array()),
);
?>
<div>
<?php ?>
<?php
$model= new Inventory;
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'ph-drug-grid',
'dataProvider'=>$model->search(),
'type'=>'bordered condensed',
'template'=>'{summary}{pager}{items}{pager}',
'columns'=>array(
array(
'header'=>'S. N. ',
'value'=>'$data->inventory_code',
'type'=>'raw',
),
'description',
'manufacturer',
'minimum_order_level',
'store_id',
'stock_quantity',
array(
'header'=>'<a>Actions</a>',
'class'=>'bootstrap.widgets.TbButtonColumn',
'template' => '{dispose}',
'buttons' => array(
'dispose' => array(
'label'=>'Dispose',
'options'=>array(
'class'=>'btn btn-small',
'onclick'=>'return confirm("Are you sure, you want to dispose this drug?")'
),
)
),
'htmlOptions'=>array('nowrap'=>'nowrap'),
)
),
)); ?>
</div>
set attributes of your model, then if they are filtered in search() function of model Inventory, then result will get filtered
$model= new Inventory;
$model->category_id = 2;
you can also use CSqlDataProvider in your controller
$sql='select * from inventory where category_id=2';
$count=Yii::app()->db->createCommand('select count(*) from inventory where category_id=2')->queryScalar();
$dataProvider = new CSqlDataProvider($sql, array(
'totalItemCount'=>$count,
'keyField' => 'id',
'pagination'=>array(
'pageSize'=>10,
),
));
more info

To change the value of parameter in CGridView using Yii

I a have a basic question about CGridViews. I have the table employees stored in my DB and I am showing some of his atributs using this CGridView. The problem is that I stored all the passwords using the md5 codification, and when I want to show them I don't know how to show them without the md5 codification.
I tried it with the sentence: "'password'=>$dataProvider->employee->md5(password)," But as you can imagine it is wrong and it doesn't work. This is my CGridView with parameter password changed to this sentence.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'id'=>'employee_list',
'columns'=>array(
'id',
'name',
//'password',
'password'=>$dataProvider->employee->md5(password),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Somebody could help me? Thank you very much.
you just need to pass php code as string, Cgridview will run that string with eval function,
Please refer following code for more clarification:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'name'=>'password',
'value'=>'md5($data->password)',
),
),
));
Let say you encoded your password with base64_encode($password) then what you have to do is base64_decode($encoded_password)
from your question, is it $dataProvider->md5(password)?
maybe you can refer the code below.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'leaveapplication-grid1',
'dataProvider'=>$model->searchpersonalleave($myid),
//'filter'=>$model,
'columns'=>array(
'leave_dateapplied',
'leave_id',
array('name'=>'leave_category','value'=>'$data->getcategoryname($data->leave_category)' ), //0-annual, 1-medical, 2-emergency
'leave_startdate',
//'leave_enddate',
'leave_duration',
'leave_reason',
array(
'class'=>'CButtonColumn',
'template'=>'{view}{update}',
'buttons'=>array
(
'update' => array
(
'visible'=>'($data->getupdatefunction(17) =="Yes")',
),
),
),
),
));

cgridview related fields filtering

I have a problem that I have solved for all but one of the cgridview filters, which is a related field.
I am using a solution Seenivasan has supplied but the related field status does not get added to the string.
here is the cgridview :-
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'tbl-orders-grid',
'dataProvider'=>$dataProvider,
'afterAjaxUpdate'=>"function() {
jQuery('#Orders_date_first').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['id'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','changeYear':'true','constrainInput':'false'}));
jQuery('#Orders_date_last').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['id'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','changeYear':'true','constrainInput':'false'}));
}",
'filter'=>$model,
'columns'=>array(
array(
'name'=>'id',
'type'=>'raw',
'value'=>'str_pad($data->id,8-strlen($data->id),"0",STR_PAD_LEFT)',
'htmlOptions'=>array('style' => 'text-align: right;width: 60px;')
),
array(
'name'=>'date_order_placed',
'filter'=>$dateisOn,
'value'=>'date("d-m-Y",strtotime($data->date_order_placed))',
),
array(
'name'=>'status',
'type'=>'raw',
//'htmlOptions'=>array('id' => 'order_status_search'),
'value'=>'CHtml::value($data,"status.orders_status_name")',
'filter'=>CHtml::listData(OrderStatus::model()->findAll(
array(
'select'=>array('orders_status_name'),
'distinct'=>true
)),"orders_status_name","orders_status_name")//this is the focus of your code
),
array(
'class'=>'EButtonColumnWithClearFilters',
'clearVisible'=>true,
'template'=>'{view}{email}',
'buttons'=>array
(
'email' => array
(
'label'=>'Reprint invoice and email to yourself',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/email.png',
'url'=>'Yii::app()->createUrl("orders/ureprint", array("id"=>$data->id))',
),
),
),
),
)); ?>
here is the php and js that adds the current filter values to the url.
echo CHtml::button('List Orders',array('id'=>'listelement'));
Yii::app()->clientScript->registerSCript('test','
$("body").on("click","#listelement",function(){
var str="&";
$.each($("#tbl-orders-grid input").serializeArray(),function(i,j){
str=str+j.name+"="+j.value+"&";
});
window.location="'.CHtml::normalizeUrl(array('orders/index')).'"+str;
});
');
The other filters, dates and id, work perfectly. They are added to the url above. Status is not.
1- you need to define new filters in your model serach() methode for example like
$criteria->compare('Restaurant.Name',$this->Name,true);
Restaurant is your relation key , name : value from another table related to this fk
2- you have to add value of gridview column like :
view:
array(
'name' => 'Restaurant.Name',
'header' => 'Username',
'filter' => CHtml::activeTextField($model, 'name'),
'value' => '$data->Restaurant->Name',
This link will help you
yii CGridView filter with relations

Categories