Yii Framework Forum: Exportablegridbehavior - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Exportablegridbehavior ExportableGridBehavior extension Rate Topic: -----

#1 User is offline   hozefahd 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 20-January 14

Posted 20 January 2014 - 02:10 AM

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
0

#2 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 622
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 20 January 2014 - 03:47 AM

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.
Don't be a dick.
0

#3 User is offline   hozefahd 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 20-January 14

Posted 20 January 2014 - 05:42 AM

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();

?>


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users