Yii Framework Forum: Filter In Cgridview - Retrieving The Results And Transferring To Another View - Yii Framework Forum

Jump to content

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

Filter In Cgridview - Retrieving The Results And Transferring To Another View Rate Topic: -----

#1 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 10 December 2012 - 02:22 PM

Hi everyone,

I have a cgridview where I filter the contents as I wish using the header filters in each column. It works fine but I was wondering if after filtering, I can transfer the results to another view. I would then add a button or link somewhere on the page and on clicking this button or link, I am redirected to another view with the contents coming from the gridview contents after filtering. Can someone guide me on how to do that?

Thanks beforehand
0

#2 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 11 December 2012 - 05:24 AM

Hi,

I have tried to retrieve the filter values by $_GET['Mymodel'] in another function in my controller but I get undefined index as error message. These filter values are retrieved in the actionAdmin of the controller and it works fine. Can't they be retrieved in the same way in another function of the controller?
0

#3 User is offline   faridplus 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 87
  • Joined: 28-March 12

Posted 11 December 2012 - 12:33 PM

View PostJimlam, on 11 December 2012 - 05:24 AM, said:

... Can't they be retrieved in the same way in another function of the controller?


CGridView has a property called 'ajaxUrl' which determines where GET parameters should go. something like this:

$this->widgets('zii.widgets.gird.CGridView', array(
	.....
	'ajaxUrl' => array('controller/action'),
	.....
));

What you give is what you get (WYGIWYG)

If you liked my post, just give it a +1. that's all!
0

#4 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 11 December 2012 - 02:08 PM

View Postfaridplus, on 11 December 2012 - 12:33 PM, said:

CGridView has a property called 'ajaxUrl' which determines where GET parameters should go. something like this:

$this->widgets('zii.widgets.gird.CGridView', array(
	.....
	'ajaxUrl' => array('controller/action'),
	.....
));



Hi Faridplus,

Thanks for your reply. The problem is that I want to retrieve the $_GET values in the actionAdmin of my controller and also in another action of the same controller. I have a button in the gridview page which will call the 2nd function and I need to pass the filter values to this 2nd function.
0

#5 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 11 December 2012 - 02:11 PM

Dear Friend

We can do it in the following way.

Add the following at the bottom of admin.php
<?php echo CHtml::button('Collect',array('id'=>'butt'));?>

<?php Yii::app()->clientScript->registerSCript('test','
$("body").on("click","#butt",function(){
	var str="&";
	$.each($("#test-grid input").serializeArray(),function(i,j){
		str=str+j.name+"="+j.value+"&";
		
		});
		window.location="'.CHtml::normalizeUrl(array('test/collect')).'"+str;
	});

')?>

Here test-grid is the id of Cgrid.


actionCollect method of TestController
public function actionCollect()
{
	$model=new Test('search');
	$model->unsetAttributes();
	$model->attributes=$_GET['Test'];
	$dataProvider=$model->search();
	$this->render('index',array(
		'dataProvider'=>$dataProvider
		));
}


My solution looks not that much elegant. I think we are missing some simple solution.
Kindly share with us if you get one.

Regards.
2

#6 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 11 December 2012 - 02:44 PM

View Postseenivasan, on 11 December 2012 - 02:11 PM, said:

Dear Friend

We can do it in the following way.

Add the following at the bottom of admin.php
<?php echo CHtml::button('Collect',array('id'=>'butt'));?>

<?php Yii::app()->clientScript->registerSCript('test','
$("body").on("click","#butt",function(){
	var str="&";
	$.each($("#test-grid input").serializeArray(),function(i,j){
		str=str+j.name+"="+j.value+"&";
		
		});
		window.location="'.CHtml::normalizeUrl(array('test/collect')).'"+str;
	});

')?>

Here test-grid is the id of Cgrid.


actionCollect method of TestController
public function actionCollect()
{
	$model=new Test('search');
	$model->unsetAttributes();
	$model->attributes=$_GET['Test'];
	$dataProvider=$model->search();
	$this->render('index',array(
		'dataProvider'=>$dataProvider
		));
}


My solution looks not that much elegant. I think we are missing some simple solution.
Kindly share with us if you get one.

Regards.


Dear Seenivasan,

You are a champ!!! I do not know if it is elegant or not; what I know is that it works like a charm. Thank you so much :D I will look into the code more deeply later on, in order to understand it. Thanks again
0

#7 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 13 December 2012 - 08:32 AM

Dear Seenivasan,

I am customizing the code you gave me in order to add a dynamic view in the url. It works fine with the dynamic view but I also wanted to add a parameter to it. I have tried in vain but with the added parameter, it does not work. Could you please help me. I guess it is a syntax problem. Here is the code:

	<?php echo 'Choose a report: ';$rapport = array('arrival'=>'Arrival','Detailed'=>'Detailed','Guest'=>'Guest','Summary'=>'Summary'); ?>
	<?php echo CHtml::dropDownList('rapport','Index',$rapport,array('id'=>'vw')); ?>



	<?php echo 'Report Title:'; echo CHtml::textField($titre,'',array('id'=>'titre','size'=>85,'maxlength'=>95)); ?>

	<?php echo CHtml::button('Process',array('id'=>'butt'));?>

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

<?php Yii::app()->clientScript->registerSCript('test','$("body").on("click","#butt",function()
	{
		var str="&";
		$.each($("#reservation-grid input").serializeArray(),function(i,j)
		{
			str=str+j.name+"="+j.value+"&";
		});
		alert(str);vw=$("#vw").val(); titre=$("#titre").val(); alert(titre);
		window.location="'.CHtml::normalizeUrl(array('"+vw+"', 'id'=>$titre)).'"+str;        });')?>


I also tried the following:-


window.location="'.CHtml::normalizeUrl(array('"+vw+"', 'id'=>"+titre+")).'"+str; 
but it does not work. Thanks
0

#8 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 13 December 2012 - 09:03 AM

I managed to solve it in another way. I suppose it was a problem with url encoding.

I changed the code to this:

		titre=$("#titre").val();
		var str="&id="+$("#titre").val()+"&";
		$.each($("#reservation-grid input").serializeArray(),function(i,j)
		{
			str=str+j.name+"="+j.value+"&";
		});
		window.location="'.CHtml::normalizeUrl(array('"+vw+"')).'"+str;        });')?>



It works. It's not too elegant, may be
0

#9 User is offline   Trat 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 10-January 13

Posted 26 January 2013 - 11:53 PM

Hi,

I have a similar problem that I have solved for all but one of the cgridview filters, which is a related field.

I am using the solution Seenivasan has supplied but the related status does not get added to the string.

here is the cgridview :-

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'tbl-orders-grid',
'dataProvider'=>$dataProvider,
'afterAjaxUpdate'=>"function() {
jQuery('#Orders_date_first').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['id'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','changeYear':'true','constrainInput':'false'}));
jQuery('#Orders_date_last').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['id'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','changeYear':'true','constrainInput':'false'}));
}",

'filter'=>$model,
'columns'=>array(
array(
'name'=>'id',
'type'=>'raw',
'value'=>'str_pad($data->id,8-strlen($data->id),"0",STR_PAD_LEFT)',
'htmlOptions'=>array('style' => 'text-align: right;width: 60px;')
),
array(
'name'=>'date_order_placed',
'filter'=>$dateisOn,
'value'=>'date("d-m-Y",strtotime($data->date_order_placed))',
),
array(
'name'=>'status_holder',
'type'=>'raw',
//'htmlOptions'=>array('id' => 'order_status_search'),
'value'=>'CHtml::value($data,"status.orders_status_name")',
'filter'=>CHtml::listData(OrderStatus::model()->findAll(
array(
'select'=>array('orders_status_name'),
'distinct'=>true

)),"orders_status_name","orders_status_name")//this is the focus of your code

),

array(
'class'=>'EButtonColumnWithClearFilters',
'clearVisible'=>true,
'template'=>'{view}{email}',
'buttons'=>array
(
'email' => array
(
'label'=>'Reprint invoice and email to yourself',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/email.png',
'url'=>'Yii::app()->createUrl("orders/ureprint", array("id"=>$data->id))',


),

),
),
),
)); ?>


The other filters, dates and id, work perfectly.

any help would be really appreciated :)
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