Export CGridView to CSV

I’m new to Yii framework.

How to export filtered data from CGridView (admin view) to csv?

thanks

Check this topic - http://www.yiiframework.com/forum/index.php?/topic/13715-

Yes, I read it. But the problem is, how do I get the filters applied to the grid in the controller (in ExportAction)?.

Thanks

$model->search() returns the dataprovider with the filters provided…

It does not work for me. $model->search() Select all.

In the admin view I have this code:

$this->widget(‘zii.widgets.jui.CJuiButton’, array(

        'buttonType'=>'link',


        'name'=>'btnGoExportar',


        'caption'=>'Exportar Compras',


        'options'=>array('icons'=>'js:{secondary:"ui-icon-extlink"}'),


        'url'=>array('exportar'),


    ));

And in the controller:

public function actionExportar()

{


   


    $model = new Ventas('search');


	$model->unsetAttributes();


    


    if (isset($_GET['Ventas']))


		$model->setAttributes($_GET['Ventas']);


    


            


    header( "Content-Type: application/vnd.ms-excel; charset=utf-8" );


    header( "Content-Disposition: inline; filename=\"ventas.csv\"" );


   


    $dataProvider = $model->search();


    $dataProvider->pagination = False;


    


    foreach( $dataProvider->data as $data )


         echo $data->idVenta, ";", $data->ApodoCliente, "\n";


            


    Yii::app()->end();


           


    


$this->render('admin', array(


	'model' => $model,


    ));


}

Any help?. Thanks.

Are you getting the filter values in $_GET[‘Ventas’] ?

No, that’s the problem. Do you know why?

Thanks.

Because you are not sending them :)

Ok. How I send it?

Thanks.

try this article http://www.yiiframework.com/wiki/306/exporting-cgridview-results-to-csv-file/