Printing Cgridview

I have a CGridview and I want to print my CGridview page and I did it using the script.

Yii::app()->clientScript->registerScript(‘grabPageNo’, "

$('#getPageNum').on('click', function(event){

    var pageNumber = $('.yiiPager > .selected > a').html();





But it is working only for the current page. I want to display CGridView results with values after sorted through filter.

hello arvind

Actually I done export to pdf in my code with cgridview filter data.

for that i set the session in model’s search action, like,

$model_data = new CActiveDataProvider($this, array(





return $model_data;

In $_SESSION[‘model_data’] you get filter data then you can use it in controller or view easily.

may be it helps you.

Thanks hiral. I am checking it.

Hiral, I am just getting an instance of CActiveDataProvider Object like this not the filtered data.

CActiveDataProvider Object


[modelClass] => ConsultationNew

[model] => ConsultationNew Object


        [patient_name] => 

        [patient_id] => 

        [dob] => 

        [gender] => 

        [age] => 

        [gender_desc] => 

        [prefer_language_id] =>

can you tell me please how you write your code?

In Controller you can write like:



		 	$d = $_SESSION['model_data'];

		 	$model = array();


			$model[]=array_keys($d->data[0]->attributes);//headers: cols name






			foreach ($d->data as $item)


			    $model[] = $item->attributes;




you can get output something like:



    [0] => Array


            [0] => Userid

            [1] => username


    [1] => Array


            [Userid] => 1

            [username] => hiral



    [2] => Array


            [Userid] => 2

            [username] => ravi



Thanks Hiral,

Although I got the answer, I am not clear about few things. Please tell me about the two things

what is $_SESSION[‘model_data’]?

and thanks a lot for giving me a solution. waiting for your answer. ::)

welcome ,

it is the session variable.

see my previous post in that i set the session variable in model and then use it in controller.