Question

i am using the cgridview widget to display some data and using pagination too. but the problem i am have is i need to replace the pagination div. i need to place it on the footer of page like

<div id="footer">
  <div id="pagination">
    <!-- pagination: << < 1 2 3 4 > >>  --> 
  </div>
</div>

but when i check the html code the pagination div is automatically created by the widget, some div like

<div class="pager">
   <!-- pagination: << < 1 2 3 4 > >>  -->
</div>

is any solution to do like this...

thanks in advance..


EDITED : as per LDG's post my code is

$pageSize = Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']);

                    $widget = $this->widget('zii.widgets.grid.CGridView', array(
                        'id' => 'request-grid',
                        'dataProvider' => $model->search(),
                        'cssFile' => Yii::app()->baseUrl . '/media/css/gridview.css',
                        'summaryText' => '',
                        'enablePagination' => true,
                        'template'=>'{items}',
                        'pagerCssClass'=>'pager',
                        'pager' => 1,
                        'pager' => array(
                            'cssFile' => Yii::app()->baseUrl . '/media/css/gridview.css',
                            'header' => false,
                            'firstPageLabel' => 'First',
                            'prevPageLabel' => 'Previous',
                            'nextPageLabel' => 'Next',
                            'lastPageLabel' => 'Last',
                        ),
                        'columns' => array(
                            array(
                                'name' => 'id',
                                'header' => '#',
                                'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
                            ),
                 ........................................
                            ));

                    ?>
                    <div id="grid-view-footer">
                        <div class="paginationholder">
                            <div id="pagination">
                                <div class="floatright">
                                    <div class="pagers">
                                        <?php $widget->renderPager(); ?>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="recordspageholder">
                            <div class="recordsperpage">Records per page
                                <?php //echo $this->pagination; ?>
                                <?php echo CHtml::dropDownList('pageSize', $pageSize, array(1 => 1, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 100 => 100), array('onchange' => "$.fn.yiiGridView.update('request-grid',{ data:{pageSize: $(this).val() }})",)); ?>
                            </div>
                        </div>

comment on ldg :but a small problem. i use a drop down box to show records per page. CHtml::dropDownList('pageSize', $pageSize, array(1 => 1, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 100 => 100), array('onchange' => "$.fn.yiiGridView.update('request-grid',{ data:{pageSize: $(this).val() }})",));. but when i change the records per page the pagination is not get updated. like if i have 20 records in db, when i select 40 records per page the pagination part is also rendering. is any solution for that. i will updated the code in my question please review it. thanks..

Was it helpful?

Solution

If you don't need to change the mark-up, you don't need to extend any classes. (And if you do want to change how the pager looks, you can do most of that in CSS.)

define your widget with a variable something like this:

$widget = $this->widget(
    ...
    'template'=>'{sorter}{items}'
    ...
);

(change the template attribute to whatever works best for you.)

then you can call:

$widget->renderPager();

elsewhere in your view.

OTHER TIPS

You cant divide a widget by sections. You can extend CGridView and redefine renderPager method.

now it looks like this:

public function renderPager()
{
    if(!$this->enablePagination)
        return;

    $pager=array();
    $class='CLinkPager';
    if(is_string($this->pager))
        $class=$this->pager;
    else if(is_array($this->pager))
    {
        $pager=$this->pager;
        if(isset($pager['class']))
        {
            $class=$pager['class'];
            unset($pager['class']);
        }
    }
    $pager['pages']=$this->dataProvider->getPagination();

    if($pager['pages']->getPageCount()>1)
    {
        echo '<div class="'.$this->pagerCssClass.'">';
        $this->widget($class,$pager);
        echo '</div>';
    }
    else
        $this->widget($class,$pager);
}

You can write your own method. And you can add div with your own id

I know it is a very old post, still if anyone is just looking for a way to override the class generated in that div in the pager, use this:

$this->widget('zii.widgets.grid.CGridView', array(
    'pagerCssClass'=>'newclass',
    ....

The generated div will be

<div class="newclass">
   ....
</div>

Worked for me in Yii 1.1.17, didn't try any previous.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top