Cgridview

Hello,

I want to apply two buttons "search" and "reset" on cgrid view in the first row (near filters).

As by default Cgridview search on enter and there is no reset option.

And? What’s your question?

Did you already search about this everywhere?

Did you already tried something?

Do you have some error?

I won’t make the job for you, I don’t know for other but I think that if you don’t show that you already look for something, less people will help you…

My point of vue.

Hi,

Try this




   array(

        'class'=>'CButtonColumn',

	...

	'header'=>CHtml::resetButton('Reset', array('onclick'=>'window.location.reload()')),

	...

   ),



currently I am using this code to reset the search

I used the Extention (EButtonColumnWithClearFilters)

Grid view extention


<div class="container">

	<div class="col-md-12">

		


		<h1>Users</h1>

		

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

			'id'=>'users-grid',

			'dataProvider'=>$model->search(),

			'filter'=>$model,

			'cssFile'=>false,

			'itemsCssClass'=>'table table-striped',

			'htmlOptions' => array('class' => 'table-responsive', 'id'=>'table-responsive'),

			'columns'=>array(

				array(

				    'name'=>'FIRST_NAME',

				    'htmlOptions'=>array('width'=>'100'),

				  ),

				array(

				    'name'=>'LAST_NAME',

				    'htmlOptions'=>array('width'=>'100'),

				  ),

				'TITLE',

				'PHONE_NUMBER',

				array(

				    'name'=>'EMAIL',

				    'htmlOptions'=>array('width'=>'100'),

				  ),

				'COMPANY',

				array(

				    'name'=>'EMAIL_VERIFIED',

				    'htmlOptions'=>array('width'=>'150'),

				  ),

				'COUNTRY',

				array(

				    'name'=>'ACCOUNT_TYPE',

				    'htmlOptions'=>array('width'=>'150'),

				  ),

				array('name'=>'Status',

						'value'=>'Yii::app()->params["userStatus"][$data->STATUS]'),

				array(

					'class'=>'EButtonColumnWithClearFilters',

					'deleteConfirmation'=>false,

					'deleteButtonImageUrl'=>Yii::app()->params['themeImage'].'/green.png',

					'header' => 'Action',

					'htmlOptions'=>array('width'=>'100px;', 'align'=>'center'),

					'template' => '{viewMeeting} {viewBilling} {delete} {activate}',

					//'template' => '{viewMeeting} {viewBilling} {delete} {update}',

					'buttons'=>array(

						'delete'=>array(

							'label'=>'Deactivate',

							'visible'=>'($data->status==1)?true:false;',

						),

				        'viewMeeting' => array(

				            'label'=>'View Meeting', // text label of the button

				            'url'=>"CHtml::normalizeUrl(array('view', 'id'=>\$data->id))",

				            'imageUrl'=>Yii::app()->params['themeImage'].'/meeting.png',

				            'options'=>array('style'=>'padding-right:5px'),

				        ),

				        'viewBilling' => array(

				            'label'=>'View Billing', // text label of the button

				            'url'=>"CHtml::normalizeUrl(array('billing', 'id'=>\$data->id))",

				            'imageUrl'=>Yii::app()->params['themeImage'].'/bill.png',

				            'options'=>array('style'=>'padding-right:5px'),

				        ),

				       'activate'=>array(

							'label'=>'Activate',

							'options'=>array('class'=>'delete'),

							'imageUrl'=>Yii::app()->params['themeImage'].'/red.png',

							'visible'=>'($data->status==0)?true:false;',

							'url'=>'Yii::app()->controller->createUrl("delete",array("id"=>$data->id))',

							),

				    ),

				),

			),

		)); ?>

		

	</div>

</div>


<script type="text/javascript">

	$(document).ready(function(){

		$('#js_search_admin').click(function(){

		$('#table-responsive').yiiGridView('update', {

				data: $(this).serialize()

			});

			return false;

		});

	});	

</script>

This extension should give you the clear filters option that you wanted in the OP. The search function is auto generated when you ‘hit enter’ in the filter box. You could use the advanced search that is in the GII generated CRUD.

Now the question is: Is the above extension working for the clear function? IF you NEED two buttons look in the code for the extension to see how the 1 button has generated. You could make your own component that does what you want.

Okay, I want to make search happen when user clicks on a button not hitting the enter in filter box or clicking outside the filter box.

Is it possible to remove the default search javascript and apply same javascript on button?

I think you would have to overwrite the javascript that triggers the default search action of the grid. Don’t know where it is. Look through the source code. The script that is used to in the default search would then have to be attached/written into the onClick event of the button.