Export CGridView to CSV

I’m new to Yii framework.

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


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)?.


$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(



        'caption'=>'Exportar Compras',




And in the controller:

public function actionExportar()



    $model = new Ventas('search');



    if (isset($_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";





$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?


Because you are not sending them :)

Ok. How I send it?


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