Eexcelview - Export Search Result Grom Tbgridview

Hello. I’ve a little problem with EExcelView.

I added eexcelview and phpmyexcel to my app.ext. Then i created additional action in my controller:




        public function actionEksport()

        {

            // Load data

            $model = Obs::model()->findAll();


            // Export it

    $this->toExcel($model,

        array(

         'col1',

         'col2',

        ),

        'Eksport',

        array(

            'creator' => 'admin',

        ),

        'Excel2007' // This is the default value, so you can omit it. You can export to CSV, PDF or HTML too

    );

        }



Everythings works fine, data are exported when i click button in my view, which called action controller/eksport. But i want to export data, which are only displayed on screen (for example, search result from "advanced search" etc…)

Can anyone help me?

Many thanks

Tom


findAll()

always will be load all data (without params).

For example if you use "default advanced search" you can do it so:




$model=new Obs('search');

if(isset($_GET['Obs'])){

    $model->attributes=$_GET['Obs'];

}

$this->toExcel($model->search(),...);



Unfortunatelly it doesn’t work well. When i pasted your code, it return data, which have not nothing similiar to my search result:(

What does the function toExcel look like?

This is one way I’ve implement it before.





public function actionSalesReport()

{

	$startDate = $_GET['Order']['reportStartDate'];

	$endDate = $_GET['Order']['reportEndDate'];


	$criteria = new CDbCriteria();

	$criteria->condition = 'state=:orderState';

	$criteria->params = array(

		':orderState' => Order::STATE_COMPLETED

	);

	$criteria->addBetweenCondition('requested_shipping_date', '' . $startDate . '', '' . $endDate . ' 23:59:59 ');


	$dataProvider = new CActiveDataProvider('Order', array(

			'criteria' => $criteria

		));


	$this->widget('ext.phpexcel.EExcelView', array(

		'dataProvider' => $dataProvider,

		'grid_mode' => 'export',

		'columns' => array(

			'id',

			'date_created',

			'item_total',

			'shipping_total',

			'tax_amount',

			'total',

			array(

				'type' => 'raw',

				'header' => 'Shipping Address',

				'value' => 'Yii::app()->controller->widget("ext.BNDComponents.widgets.BNDAddressWidget.BNDAddressWidget", array(

					"address" => ($data->is_delivery) ? $data->shippingAddress : $data->pickupArea,

					"format" => BNDAddressWidget::FORMAT_MAPPABLE

				), true)'

			),

			'requested_shipping_date',

			'requested_shipping_time',

			'first_name',

			'last_name',

			'email',

			'phone',

		)

	));


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

}



Matt

I’m using this extensions: http://www.yiiframework.com/extension/toexcel . This extensions compile eexcelview and phpexcel

I think that problem is, that when i search and filter data i have for example url like this: http://example.com/obs/all?Obs[col1]=sth&Obs[col2]=other&Obs_page=1

, and when i try to execute my export action, url look like: http://example.com/obs/eksport - and it export data without parameters - simply, actionEksport don’t know criteria…

So your $_GET/$_POST environment variables are empty? This thread shows how to serialize the form and post it to your export action.

Ok, thanks for reply:)