Exporting Filtered Data From Cgridview To Pdf, Csv

I am using PHPExcel extension to export data displayed in Cgridview to excel and pdf files. But I am not able to export only filtered data. How can I do this?

My Controller action is:

public function actionToExcel() {

         $model = new Orders('storesearch');


         $model->unsetAttributes();


         $d = $_SESSION['orders-excel'];


         $factory = new CWidgetFactory();


         $widget = $factory->createWidget($d, 'EExcelView', array(


            'dataProvider' => $model->storesearch(),


            'grid_mode' => 'export',


            'title' => 'Title',


            'filename' => 'report',


            'stream' => TRUE,


            'exportType' => 'Excel2007',


            'disablePaging'=>false,


             'columns' => array(


                                'id',





             array(


                'name'=>'date',


                'value'=>'$data->date'


            ), 








            array(


                    'name'=>'company_name',


                    'value'=>'$data->com_name->company_name',


            ),


	'customer_info',


	'order_id',


	'tracking_id',


	'invoice_id',


	'invoice_amount',


            array( 


			'name'=>'status',


			'header'=>'status', 


			'filter'=>array(


				'0'=>'Returned',


				'1'=>'Completed'


			), 


			'value'=>'($data->status=="1")?("Completed") : ("Returned")' 


		),





            ),


        ));


        $widget->init();


        $widget->run();


        exit;


        


        


    }

And My Model is:

public function storesearch()

{


	// @todo Please modify the following code to remove attributes that should not be searched.





	$criteria=new CDbCriteria;


            


            if((isset($this->date_first) && trim($this->date_first) != "") && (isset($this->date_last) && trim($this->date_last) != ""))


            $criteria->addBetweenCondition('date', ''.$this->date_first.'', ''.$this->date_last.'');





            $criteria->compare('t.id',$this->id);


	$criteria->compare('store',$this->store,true);


	$criteria->compare('customer_info',$this->customer_info,true);


	$criteria->compare('order_id',$this->order_id,true);


	$criteria->compare('tracking_id',$this->tracking_id,true);


	$criteria->compare('invoice_id',$this->invoice_id,true);


	$criteria->compare('date',$this->date,true);


	$criteria->compare('invoice_amount',$this->invoice_amount);


	$criteria->compare('t.status',$this->status,true);


	$criteria->with = array('com_name');


	$criteria->compare('com_name.company_name',$this->company_name,true);


	$data = new CActiveDataProvider($this, array(


                    'criteria'=>$criteria, 


                    'sort'=>array(


                            'attributes'=>array(


                                'company_name'=>array(


                                    'asc'=>'com_name.company_name',


                                    'desc'=>'com_name.company_name DESC',


                                ),





                                '*',


                            ),


                        )


	));


            


            $_SESSION['orders-excel']=$data; // get all data and filtered data 


            return $data;





}

please use [code] tag. it’s impossible to understand what you want.

I think you may need to look at serialize()

I might also look at saving only the $criteria and then use it with a new CDataProvider in the actionToExcel().

I’m not sure why you are going to all of the WidgetFactor() stuff. This may be involved with PHPExel. (It is)

Looking at the docs for ‘eexcelview’ you don’t need to save the $dataProvider since you are providing the $model->sitesearch(). Where you set $d in the widget should be $this.

From extension:

Going back to the extension page site, this is for using the widget in a console app.