I wanna show data through CGridView with pagination..
Here the problem is that the dataprovider is an array ratherthan CArrayDataProvider or CDataProvider..
How to add pagination if dataprovider is an array as shown below
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'family-record-grid',
'dataProvider'=>$arr[1],
'enableSorting' => false,
'columns'=>
array()
));
You can try this CGridView in your view file.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'family-record-grid',
'dataProvider'=>$model->search(),
'afterAjaxUpdate' => 'function(){}',
'htmlOptions' => array('class' => 'form-inline', 'role' => 'grid'),
'ajaxUrl' => Yii::app()->createUrl('controllername/actioname'),
'ajaxUpdate' => true,
'enablePagination' => true,
"summaryText" => true,
'itemsCssClass' => 'responsive dataTable', // Item CSS Class
"template" => "{items}\n{summary}{pager}",
"summaryText" => "Showing {start} to {end} of {count} entries",
'pagerCssClass' => '', // Page CSS Class
'pager' => array(
'class' => 'CLinkPager',
'maxButtonCount' => 5,
'nextPageLabel' => 'Next',
'prevPageLabel' => 'Prev',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
),
'selectableRows' => 2,
'enableSorting' => false,
'columns'=>array()
)
);
Related
I Want to open a CJuiModel by Clicking on CGridView CButtonColumn view Button as my CGridView and CJuiModel is as:-
<?php
$dataProvider = new CArrayDataProvider($model->exhibitorLocation, array(
'keys' => array('productId'),
));
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'id' => 'exhibitor-location-grid',
'summaryText' => false,
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
),
'columns' => array(
array(
'header' => 'S No.',
'value' => '++$row',
),
array(
'header' => 'Hall No',
'value' => '$data->location->hallNo',
),
array(
'header' => 'Stand No',
'value' => '$data->standNo',
),
array(
'class' => 'CButtonColumn',
'header' => 'Manage',
'template' => '{view}{delete}',
'buttons' => array(
'view' => array(
'imageUrl' => $this->module->assetsUrl . "/images/info_icon.png",
'options' => array('class' => 'exb-location'),
'url' => 'Yii::app()->createUrl("admin/venuemap/viewExbLocation", array("exbLocId"=>$data->primaryKey))',
),
'delete' => array(
'imageUrl' => $this->module->assetsUrl . "/images/delete_icon.png",
'url' => 'Yii::app()->createUrl("admin/venuemap/deleteExbLocation", array("exbLocId"=>$data->primaryKey))',
),
),
'htmlOptions' => array(
'style' => 'width:100px;float:center'
)
),
),
'rowCssClassExpression' => '($row%2 ? "visit2" : "visit1")',
'itemsCssClass' => 'visitor_list',
'htmlOptions' => array(
)
));
?>
<div class="name_field">Hall No<span>*</span></div>
<?php echo CHtml::dropDownList('hall-no', '', CHtml::listData(Venuemap::model()->findAll(), 'locationId', 'hallNo'), array('class' => 'name_input2', 'id' => 'hall-no')); ?>
<div class="name_field">Stand No</div>
<?php echo CHtml::textField('Stand No', '', array('class' => 'name_input', 'id' => 'stand-no')); ?>
<?php
echo CHtml::ajaxLink("Add Location", Yii::app()->createUrl('admin/venuemap/addExbLocation'), array(
'type' => 'post',
'data' => array(
'exhibitorId' => $model->exhibitorId,
'standNo' => 'js: $("#stand-no").val()',
'locationId' => 'js: $("#hall-no").val()'
),
'success' => 'function(html){ $.fn.yiiGridView.update("exhibitor-location-grid"); }'
), array('class' => 'search_btn'));
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'location-dialog',
'options' => array(
'title' => 'View Location',
'autoOpen' => false,
'modal' => true,
'width' => 'auto',
'height' => 'auto',
'resizable' => false
),
));
$this->endWidget();
?>
<?php
Yii::app()->clientScript->registerScript('view-location-ajax', "
$('.exb-location').click(function(){
url=$(this).attr('href');
$.ajax({
type: 'post',
url: url,
success: function(result){
$('#location-dialog').html(result).dialog('open');
$('#draggable').draggable();
return false;
}
});
return false;
});
");
?>
View Button is working fine and open a CJuiModel on click but when I add a new Location in CGridView .
On Clicking on view button my CJuiModel is not opening and page is redirecting to Url.Why my jquery is getting failed on updating CGridView. Help..
Change ajax call using JQuery 'on' instead direct event binding:
This:
...
$('.exb-location').click(function(){
...
Change for:
...
$('.exb-location').on('click', '.exb-location', function(){
...
Html Elements are destroyed and regenerated after CGridview refresh. Direct JQuery events only work with existing elements before DOM load. When they are removed, or new elements are added later, direct events don't work.
[SOLVED]
What im trying to accomplish is to put a date picker in the gridview columns and on change update mysql table.
I've got the update functions i just need help to add the datepicker in the column
THE ANSWER:
'columns' =>array(
array(
'name'=>'due_date',
'value'=>'$data->datePicker()',
'filter'=>CHtml::activeDateField($model,'due_date',array('id'=>$id,'class'=>'form-control','data-id'=> $this->id)),
'type'=>'raw',
),
),
And then the datepicker function in my model
public function datePicker(){
return CHtml::activeDateField($this,'due_date',array('id'=>$id,'class'=>'form-control updateableDate','data-id'=> $this->id));
}
Any Questions feel free
You can use this code :-
<div id="orderdiv">
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
//'model' => $model,
'name'=>'test',
'attribute' => 'created',
'language' => 'en-AU',
'i18nScriptFile' => 'jquery.ui.datepicker-en.js',
'htmlOptions' => array(
'id' => 'created',
'size' => '10',
),
'defaultOptions' => array(
//'showOn' => 'focus',
'dateFormat' => 'dd/mm/yy',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
)
));
?>
</div>
let me know is it working or not.
Try this code :-
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'orders-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'afterAjaxUpdate'=>"function(){jQuery('#due_date_search').datepicker({'dateFormat': 'yy-mm-dd'})}",
'columns'=>array(
array(
'name' => 'due_date',
'type' => 'raw',
'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array('model'=>$model, 'attribute'=>'due_date', 'htmlOptions' => array('id' => 'due_date_search'), 'options' => array('dateFormat' => 'yy-mm-dd')), true)
),
),
));
Here is my code
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'dsfsd',
'dataProvider' => $model->search(),
'filter' => $model,
'cssFile' => false,
'itemsCssClass' => 'table table-striped',
'beforeAjaxUpdate'=>'js:function(id,options){$.blockUI({
message: "Please wait",
//showOverlay: false,
css: {
border: "none",
padding: "15px",
"-webkit-border-radius": "10px",
"-moz-border-radius": "10px",
opacity: 1,
"z-index": "9999"
}
});}',
'columns' => array(
array(
'header' => '#',
'name' => 'id',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->id),array("abc/m/".CHtml::encode($data->id)."/info"))',
'htmlOptions' => array('width' => '40px'),
'filter' => CHtml::activeTextField($model, 'id', array('placeholder' => 'search by id')),
), array(
'header' => 'First name',
'name' => '$data.user.f_name',
'type' => 'raw',
'value' => 'CHtml::encode($data->user->f_name)',
), array(
'header' => 'Last name',
'name' => '$data.user.l_name',
'type' => 'raw',
'value' => 'CHtml::encode($data->user->l_name)'
),
array(
'class' => 'CButtonColumn',
'template' => '{update} {delete}',
//'updateButtonUrl' => 'Yii::app()->createUrl("abc/xyz?id=".$data->id."&c_id=".$data->c_id)',
'deleteButtonUrl' => 'Yii::app()->createUrl("xyv/abc",array("uid"=>$data->id))',
),
),
));
Well, what I want is that the operations under beforeAjaxUpdate will work only when delete button is clicked, not for any other ajax actions like on search or update. How is it possible?
You can add callback function to delete button:
http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail
You should set click option in buttons config array:
'columns' => array(
...
'buttons'=>array(
'class'=>'CButtonColumn',
'template'=>'{delete}{update}',
'buttons'=>array(
'delete'=>array(
'click'=>'function(){/*your code here*/}'
)
)
)
...
)
You can return false from callback function to prevent deleting.
I have installed in Yii 1.1
$this->widget('zii.widgets.CListView', array(
'template' => Yii::t('Site','Header News')
But how 'to do it in Yii2 ?
echo ListView::widget(['template' => Yii::t('Site','Header News'),
'dataProvider' => $tipsList,
'itemView' => '_listItem',
'layout' => '{items}{pager}',
'itemOptions' => [
],
'options' => [
'links' => '<h2>test</h2>',
'tag' => 'ul',
'class' => 'ten-vertical summary-list',
],
'viewParams' => array(
'categoryAlias' => $categories[0]->urlAlias,
'imageConfig' => array('width' => 120, 'height' => 120, 'fill' => true),
'firstImageConfig' => array('width' => 436, 'height' => 436, 'fill' => true),
),
]);
Param 'template' => Yii::t('Site','Header News') does not work
template property of ListView in Yii2 called layout. Link
Example:
'layout' => '<li class="list-header">Header</li>{items}{pager}',
'options' => [
'tag' => 'ul',
],
The li.list-header will be added into a parent tag ul
I am trying to generate a Yii GridView using Bootstrap
On the ul element, i have the yiiPager class and i need to set it as the pagination class;
code here:
<h1>Manage Request Ms</h1>
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'request-m-grid',
'type' => array('striped', 'bordered', 'condensed'),
'dataProvider' => $model->search(),
'template' => '{pager}{items}{pager}',
'filter' => $model,
'pager' => array(
'header' => '',
'hiddenPageCssClass' => 'disabled',
'maxButtonCount' => 3,
'cssFile' => false,
// 'class' => 'pagination',
'prevPageLabel' => '<i class="icon-chevron-left"></i>',
'nextPageLabel' => '<i class="icon-chevron-right"></i>',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
),
'pagerCssClass' => 'pagination',
'rowCssClass' => 'pagination',
'columns' => array(
'id',
'domain_id',
'start',
'stop',
'delta1',
'delta2',
array(
'class' => 'CButtonColumn',
),
),
));
?>
$this->widget('bootstrap.widgets.TbGridView',array(
'id' => 'request-m-grid',
....
'pager' => array('htmlOptions'=>array('class'=>'your_css_class')), // set whatever css class you want
));