pagination within tab view

Hello , i have a tab view using CTabView class , the tab view contains two tabs , the tabs are set to two

views , in each view I have a table with pagination using CLinkPager . The problem is that when suppose i am in second tab and click on next pagination button , the page is reloaded and it goes back to default tab.

I want such that if i am click on pagination button in one tab i should be in the same tab after clicking the pagination button.

Please guide me , i am stuck with this big problem

Follow below steps for your problem:

  1. Extend "MyPagination" class from CPagination:

app\protected\extensions\MyPagination.php


class MyPagination extends CPagination {

    public function createPageUrl($controller, $page) {

        $controllerId = $controller->id;

        $actionId = $controller->action->id;

        $page++;

        

        $url = Yii::app()->createUrl($controllerId . "/" . $actionId, array($this->pageVar => $page));

        return $url;

    }

}

  1. Use MyPagination class instead of CPagination in both of the rendered views:

$pages = new MyPagination($item_count);

  1. Set pageVar for pagination and gridview in both of the rendered views:

For Pagination:


$pages->pageVar = "t";



For GridView:


$dataProvider = new CActiveDataProvider('Test1', array(

        'pagination' => array('pageSize' => 3, 'pageVar' => 't')

);

  1. Manage active tab according to requested parameter in your main view:

$activeTab = '';

if (isset($_REQUEST['tp'])) {

        $activeTab = 'tab2'; 

}

else {

        $activeTab = 'tab1'; 

}


$this->widget('CTabView', array(

    'tabs' => array(

        'tab1' => array('title' => 'Test View1', 'content' => $test1View),

        'tab2' => array('title' => 'Test View2', 'content' => $test2View),

    ),

    'activeTab' => $activeTab,

    'id' => 'Tab-Id'   

));

Hope this helps.

Thanks

Saurabh Dhariwal