Pagination not working in Yii Framework - php

I am using Yii Rights modules for ACL where I want pagination for Permissions page.
Following is my code:
In AuthItemController.php
public function actionPermissions() {
$dataProvider = new RPermissionDataProvider('permissions', array(
'pagination' => array(
'pageSize' => 10,
//'class' => 'CPagination', //showing an error
'itemCount' => 32
)));
// Get the roles from the data provider
$roles = $dataProvider->getRoles();
$roleColumnWidth = $roles !== array() ? 75 / count($roles) : 0;
// Initialize the columns
$columns = array(
array(
'name' => 'description',
'header' => Rights::t('core', 'Item'),
'type' => 'raw',
'htmlOptions' => array(
'class' => 'permission-column',
'style' => 'width:25%',
),
),
);
// Add a column for each role
foreach ($roles as $roleName => $role) {
$columns[] = array(
'name' => strtolower($roleName),
'header' => $role->getNameText(),
'type' => 'raw',
'htmlOptions' => array(
'class' => 'role-column',
'style' => 'width:' . $roleColumnWidth . '%',
),
);
}
$view = 'permissions';
$params = array(
'dataProvider' => $dataProvider,
'columns' => $columns,
);
// Render the view
isset($_POST['ajax']) === true ? $this->renderPartial($view, $params) : $this->render($view, $params);
}
And in View
$this->widget('bootstrap.widgets.TbGridView', array(
'type' => 'bordered',
'dataProvider' => $dataProvider,
'template' => '{pager}{items}',
'emptyText' => Rights::t('core', 'No authorization items found.'),
'htmlOptions' => array('class' => 'grid-view permission-table'),
'columns' => $columns,
'pager' => array(
'header' => '',
'hiddenPageCssClass' => 'disabled',
'maxButtonCount' => 3,
'cssFile' => false,
'class' => 'CLinkPager',
'prevPageLabel' => '<i class="icon-chevron-left"></i>',
'nextPageLabel' => '<i class="icon-chevron-right"></i>',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
),
'pagerCssClass' => 'pagination',
));
I have already implemented pagination for other pages by using same method but here in rights module its not working. Its not showing any error but also not displaying pagination links/buttons.

I had the same problem when implementing multiple grids in one page, the solution that worked for me was , I checked the url the grid ajax call,and before update I manipulated the url, and set the correct url and parameters before ajax request!
like:
$this->widget('zii.grid.GridView', array(
'id' => 'group-grid-customers-list-not-scheduled',
'dataProvider' => $notScheduledVisitedDataProvider ,
'beforeAjaxUpdate' => '
function(id , options)
{
options.url = options.url.split("&test=test&");
options.url = options.url[0] + "&test=test&" + $(".search-form form").serialize();
}',
'columns' => array(
'col1',
'col2',
'col3',
),
));

Related

Cgridview CLinkPager returns one record less than specified in pageSize

I am using CGridView in application and setting pageSize to 10 but on loading the page it shows 9 records.
Here is my code:
Model Function returning data:
public function myTasks()
{
$criteria = new CDbCriteria();
$criteria->select = "*";
$criteria->join = 'LEFT JOIN task_assignment t2 on t.id=t2.task_id';
$criteria->condition = "t2.task_id is NULL AND t.user_id=" . Yii::app()->user->id;
$criteria->compare('t.task_title', $this->task_title, true);
$criteria->compare('t.task_description', $this->task_description, true);
$criteria->compare('t.project_id', $this->project_id, true);
$criteria->addCondition("t.status!='Deleted'");
$criteria->distinct = true;
$criteria->order = 'id desc';
return new CActiveDataProvider('Task', array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 10
),
));
}
Here is my view:
Yii::app()->clientscript->scriptMap['jquery.js'] = FALSE;
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->myTasks(),
'summaryText' => '',
'emptyText' => 'There are no tasks to dispaly',
'itemsCssClass' => 'table table-striped',
'pagerCssClass' => 'dataTables_paginate paging_bootstrap text-center paginationBg',
'pager' => array(
'prevPageLabel' => '‹ Previous',
'nextPageLabel' => 'Next ›',
'firstPageLabel' => '« First',
'lastPageLabel' => 'Last »',
'header' => '',
'htmlOptions' => array('class' => 'pagination')
),
'htmlOptions' => array(
'class' => 'table-responsive',
'id' => "my-task-grid"
),
'columns' => array(
array(
'name' => 'task_title',
'value' => '$data->task_title',
'type' => 'raw',
)
)
));
Also if I click page number 2 and then click on page 1 back then it returns correct 10 results.
Any ideas?
Thanks for your help.

Ajax Request is Not Working After CGridView Update

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.

Prestashop override admin template

I have the code (for prestashop 1.5):
class AdminTestController extends AdminController
{
public $identifier = 'id_test';
function __construct() {
parent::__construct();
$this->table = 'test';
$this->className = 'test';
/*$this->fields_list = array(
'id_test' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'content' => array('title' => $this->l('Test'), 'width' => 'auto')
);*/
$this->fields_options = array(
'general' => array(
'title' => $this->l(''),
'icon' => 'tab-preferences',
'fields' => array(
'TEST' => array(
'type' => 'textarea',
'label' => $this->l('TEST'),
'title' => $this->l('TEST'),
'name' => 'test',
'autoload_rte' => true,
'lang' => true,
'rows' => 15,
'cols' => 70,
//'hint' => $this->l('Invalid characters:').' <>;=#{}'
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
)
);
}
}
I want to attach tinyMCE to my textarea. I need to override one template but I can't find which one.
I tried:
template/controllers/test/list/list.tpl
template/controllers/test/form.form.tpl
How can I override the template for my controller?
Just for information. I override option/option.tpl; Now it works.

beforeAjaxUpdate on delete cgridview yii

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.

Yii Bootstrap GridView yiiPager replacement

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
));

Categories