Yii Export Results

As you can see above, I want to submit the form on the click of the Menu ie [Export…].

So that by whatever criteria i did search will also carry for the Export, except the pagination.

Please Help me!!!

Hello Chintan Shah,

as I see you need to think to Export to Excel inside search box, not a separated operation (controller action). If you need the parameters issued in the search box is easy to see why…

See this example: http://www.yiiframework.com/forum/index.php/topic/20144-export-a-search-results-to-excel/page__view__findpost__p__98553

You will need to change a few Views and the Controller and perhaps some minor changes onto the Model.

Hope it helps,

cbi

Hey cbi,

Thanks for the Reply, I tried it already, but by yr way, it breaks my working functionality…

like, when i click on search, it doesn’t pass the params. so the basic things gone wrong…

and even on Sorting and pagination… i m loosing my selected params… so if u can help me on that… i m ready for that way also…

Mmmh, are you trying with the example I’ve recommended you? By adding a new button at search box you complement actionAdmin() and search() functions… you can access Model parameters 'cos you’re at controller actionAdmin() !!

If you add a new operation/action “link”, you’ll need to append current search’ parameters which exists inside search form aside from sort and page params…

Best,

cbi

here is the code of View file, above grid…


Yii::app()->clientScript->registerScript('index', "

$('#submit-button').click(function(){ 

        $.fn.yiiGridView.update('search-grid', {

                data: $('.search-form form').serialize()

        });

        return false;

});

");

Buttons HTML:




$form=$this->beginWidget('CActiveForm', array(

	'id'=>'search-form',

	'enableAjaxValidation'=>false,

	'method'=>'post',

)); ?>

<div class="searchrRow" >

	<div class="leftDiv" >	

	<?php 		

		echo $form->labelEx($smodel,'E_NAME');

		echo CHtml::activeDropDownList($smodel,'E_ID', $dmodel->getEmployees(),array('prompt'=>'Select'));

		echo '</div><div class="rightDiv">';

		echo $form->labelEx($smodel,'D_NAME',array('class'=>'labelPadding'));

		echo CHtml::activeDropDownList($smodel,'E_DEPTID', $emodel->getDeptTypes(),array('prompt'=>'Select'));

		echo '</div><div class="rightDiv">';

		echo $form->labelEx($smodel,'TYPE');

		echo CHtml::activeDropDownList($smodel,'LS_LTYPEID', array('0'=>'Leaves','1'=>'Comp Off', '2'=>'Both') ,array('class'=>'smallDropDown'));

	?>

	</div>

	<div class="searchDiv">

<!--		<button class="btn" type="submit"> Search </button> -->

		<?php echo CHtml::submitButton('Search', array( 'id'=>'submit-button','name'=>'submit-button')); ?> 

	</div>

</div>

<div style="clear:both;"></div>

<div class="searchrRow">

	<div class="leftDiv">

	<?php 

		echo $form->labelEx($smodel,'LS_FROM');

		$this->widget('zii.widgets.jui.CJuiDatePicker', 

			array(

				'name'=>'Search[LS_FROM]',

				'model'=>$smodel,

				'attribute'=>'LS_FROM',

				'options'=>array(

					'showAnim'=>'fold',

					'dateFormat'=>'yy-mm-dd',

				),

				'htmlOptions'=>array(

					'readonly'=>"readonly"

				),

		));				

		echo $form->error($smodel,'LS_FROM');

		echo '</div><div class="rightDiv">';

		echo $form->labelEx($smodel,'LS_TO',array('class'=>'labelPadding'));

		$this->widget('zii.widgets.jui.CJuiDatePicker',

			array(

				'name'=>'Search[LS_TO]',

				'model'=>$smodel,

				'attribute'=>'LS_TO',

				'value'=>'dd-mm-yy',

				'options'=>array(

				'showAnim'=>'fold',

				'dateFormat'=>'yy-mm-dd',

			),

			'htmlOptions'=>array(

				'readonly'=>"readonly"					

			),

		));				

		echo $form->error($smodel,'LS_TO'); 

		echo '</div><div class="rightDiv">';

		echo $form->labelEx($smodel,'LS_STATUS');

		echo CHtml::activeDropDownList($smodel,'LS_STATUS', $lsmodel->getAllStatus(),array('prompt'=>'Select'));

		echo $form->error($smodel,'LS_STATUS');

	?>

	</div> 

	<div class="searchDiv">

		<a onclick="javascript:clearAll(1);"> Clear All </a>

	</div>

</div>

<div style="clear:both;"></div>

<?php echo CHtml::submitButton( 'Export', array( 'id' => 'export', 'name' => 'export' ) ); ?>

<?php $this->endWidget(); ?>

just by adding this code, i lost my working functionality of search…means it is not caring my criteria to controller.

"[font="Courier New"]search-grid[/font]" is the id of your CGridView ??

cbi

Yes


Yii::app()->clientScript->registerScript('index', "

$('#submit-button').click(function(){ 

        $.fn.yiiGridView.update('search-grid', {

                data: $('.search-form form').serialize()

        });

        return false;

});

");


$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'search-grid',

	'dataProvider'=>$smodel->searchResultSql(),

	'showTableOnEmpty'=>false,

	'columns'=>array(

		array(

			'name'=>'E_NAME',

			'header'=>'Employee',

			'type'=>'raw',

			'value'=>'$data["E_NAME"]',

			'sortable'=>'true',

		),

		array(            // display Dept Name

            'name'=>'E_DEPTID',

			'header'=>'Deparment',

			'type'=>'raw',

			'value'=>'$data["DPTNAME"]',

		),

		array(

			'name'=>'E_TLID',

		    'header'=>'Leader',

		    'value'=> '$data["TLNAME"]',

			'type'=>'raw',

        ),

		array(            // display From Date 

            'name'=>'LS_FROM',

			'header'=>'From',

			'type'=>'raw',

			'value'=>array($smodel,'getFromDate'),

		),

		array(            // display To Date

            'name'=>'LS_TO',

			'header'=>'To',

			'type'=>'raw',

			'value'=>array($smodel,'getToDate'),

		),

		array(            // display Leave Status

            'name'=>'LS_STATUS',

			'header'=>'Status',

			'type'=>'raw',

            'value'=>'$data["LS_STATUS"]',

		),

		array(            // display Leave Days 

            'name'=>'LS_DAYS',

			'header'=>'Days',

			'type'=>'raw',

            'value'=>'$data["LS_DAYS"]',

		),

		array(            // display Type

            'name'=>'TYPE',

			'type'=>'raw',

            'value'=>array($smodel,'getTypeName'),

			'sortable'=>true,

		),

	), 

));

Try to add to your CGridView:


'ajaxUpdate'=>false

this will avoid Ajax and see if your actionAdmin() receive the params…

cbi

now form is submitting but, params are not carrying over there… :(