Exportablegridbehavior

Hi,

I am trying to export the result from the grid of yii. But as the data to the grid is provided by a array, i am not able to export the grid result.

Following code i am calling in my controller




        $productData = $this->outofstockProduct();

        $dataProvider2 = new CArrayDataProvider(

                $productData, array(

                        'sort'=>array(

                        'attributes'=>array('id','*'),

                        //'defaultOrder'=>array('entity_id' => false),

                ),

                        'pagination'=>array(

                        'pageSize'=>10,

                ),

        ));

        if ($this->isExportRequest()) { //<==== [[ADD THIS BLOCK BEFORE RENDER]]

            //set_time_limit(0);

             $this->exportCSV($dataProvider2, array('id',

		'name',

		'category',

		'code'));

                 

        }

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

                'dataProvider'=>$dataProvider2,

        ));



// following is the way i am exporting the result in view pages




<?php $gridWidgetProduct = $this->widget('zii.widgets.grid.CGridView',array(

    'id'=>'product-grid',

    'dataProvider' => $dataProvider,

    'columns'=>array(

        'id',

        'name',

        'category',

        'code',

     )

    ));

?>

<?php

$this->renderExportGridButton($gridWidgetProduct,'Export Grid Results',array('class'=>'btn btn-info pull-right'));

?>



Can any please help to rectify my mistake

What’s the problem? You got any error message?

Please use the [code][/code] blocks when pasting code. Also, you can try my exporter module, it works with really large datasets.

I installed the exporter module. But does not have proper documentation. Put the following code in my view page.

But give an error.




<?php

$widget = Yii::app()->widgetFactory->createWidget($controller, 'ext.exporter.CsvView', array(

    'columns'=>array(

        'id',

        'name',

        'category',

        'code',

     ),

    'dataProvider' => $dataProvider, // or create it any other way

    'disableBuffering' => false,

    'disableHttpHeaders' => true,

));

ob_start();

ob_implicit_flush(false);

$widget->run();

$file_contents = ob_get_clean();


?>