How to customize Yii CGridView Pager? - php

How to customize Yii CGridView Pager about its position, css, template?

You can custumize via 'pager' CGridView properties. Example:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'My-grid',
'dataProvider'=>$dataProvider,
'pager'=>array(
'header' => '',
'firstPageLabel' => '<<',
'prevPageLabel' => '<img src="images/pagination/left.png">',
'nextPageLabel' => '<img src="images/pagination/right.png">',
'lastPageLabel' => '>>',
),
'template'=>'{pager}{items}{pager}',
'columns'=>$arrayColumns,
));

http://www.yiiframework.com/doc/api/CBaseListView#pager-detail
http://www.yiiframework.com/doc/api/CBaseListView#pagerCssClass-detail
http://www.yiiframework.com/doc/api/CLinkPager

Here's another approach which worked for me.
Displaying Yii's CLinkPager "First" and "Last" Buttons
If you have troubles, make sure to read the comments below the entry.

Related

Yii Framework: Pagation Callback Method

I have a CListView on a page and every time i navigate to page 2 or any other page I want to call a method that formats the view. But it do not seem to work every time I navigate to another page.
The Javascript method I want to call is called updateDivs()
Here is my list view widget
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_customview',
'id' => 'bannerslist',
'ajaxUpdate' => true,
'afterAjaxUpdate' => ' updateDivs()',
'enablePagination' => true,
'itemsCssClass' => 'row banners-list',
'summaryText' => 'Total ' . $pages->itemCount . ' Results Found',
'pager' => array(
'header' => '',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
));
Please try this to test, it should works well.
'afterAjaxUpdate' => 'js:function(id,data){alert("test");}'
So if this code will works perfect then you should search problem in your updateDivs() function
Your problem is that, you missed to write js:function(id, data) which is significant to call a method.
You can use as follows :
'afterAjaxUpdate'=>'js:function(id, data) {updateDivs();}',
Look here for more info.

Jquery attr doesnt work on Yii

I'm trying to change the element value using Jquery but it's not working...
This is my widget where I have my element 'tag' which i want to change it to textField on edit...
$this->widget('EditableGrid', array(
'dataProvider' => $dataProvider->searchbyID($invoice_id),
'template' => '{items}{buttonCreateRow}{pager} ',
'id' => 'InvoiceLine-grid',
'rowTemplate' => $row_template,
'columns' => array(
array(
'class' => 'EditableGridColumn',
'header' => '',
'name' => 'InvoiceLine_{gridNum}_{rowNum}_edit',
'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
'tag' => 'button',
'tagHtmlOptions' => array(
'onclick'=>'editline(this)',
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'StentysRef',
'name' => '[{gridNum}][{rowNum}]stentysproductref',
'tag' => 'laabel',
'tagHtmlOptions' => array(
'style'=>'background-color:#FFF;border-color:#FFF',
'onkeyup'=>'stentysref(this)',
'readonly'=>true
)
),
My Jquery is,
(as you can see the removeAttr works but attr doesn't)
function editline(obj){
$("#InvoiceLine_1_"+row+"_stentysproductref").attr("tag","textField");
$("#InvoiceLine_1_"+row+"_stentysproductref").removeAttr("readonly");
}
Use .prop() and removeProp() which is added in jQuery 1.6, as the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior.
function editline(obj){
$("#InvoiceLine_1_"+row+"_stentysproductref").prop("tag","textField");
$("#InvoiceLine_1_"+row+"_stentysproductref").removeProp("readonly");
}
API Doc for .prop()
If you are using EditableGrid widget without pointing AR model, then the row id looks like
$('#_1_'+row+'stentysproductref').
I'll take it into consideration for the future updates. Thank you.

how do i change the alignment of yii framework pager?

<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view',
'ajaxUpdate' => true,
'pager' => array(
'class' => 'CLinkPager',
),
'template' => '{pager}{items}',
));
?>
after executing this the pager components are displaying as column format.is their any way to change that into row format?
I guess you getting this widget through renderPartial() method. When using the renderPartial() method controller not sending js and css files with response by default. If you want to get response with these files you should pass true in fourth parameter:
$this->renderPartial('myView',array(), false, true);

Append some html text to a Yii Widget

I have the following Yii widget and want to pass some html at the just before and just after the items are iterated through- can anyone explain how I do this?
$this->widget('application.widgets.zii.ListViewShowAll', array(
'summaryText' => false,
'template' => '{items}',
'htmlOptions' => array(),
'itemView' => 'application.views.widgets.account.prizes._mainprizeItem',
);
Just amended the widget code above...
'template' => '{<p>someting</p> items <p>more text</p>}',

Changing page labels (clistview, cgridview) witout changing pager css (bootstrap)

When I set 'pager' in CGridView it change bootstrap look, I try with cssFile to null or false, it doesn't work.
'pager' => array(
'class' => 'CLinkPager',
'firstPageLabel' => '<<',
'prevPageLabel' => 'smthprev',
'nextPageLabel' => 'smthnext',
'lastPageLabel' => '>>',
),
The Bootstrap extension checks if htmlOptions['class'] is set , i.e : isset($htmlOptions['class']), so if we set empty class, then it should work. So add this:
'pager' => array(
// rest of code
'htmlOptions'=>array('class'=>'')
),

Categories