dropDownList in cgridview

Hi, friends

In my Cgridview contains dropDownlist. In dropdownlist,url, I want to be like this: index.php/order/ChangAction?order_id=120, but i tried code as show below, can’t get the order_id value. contrast, I got like this: index.php/order/ChangAction/

please help me.

thanks.





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

	'id'=>'order-grid',


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

	'filter'=>$model,

	'columns'=>array(

		'created_date',

		'order_id',

		array(

		'name'=>'customer_id',

		'value'=>'Customers::model()->findByPk($data->customer_id)->customer_first_name." ".Customers::model()->findByPk($data->customer_id)->customer_last_name'

		),

		'order_status',

		'address',

               array(

                'header'=>'Action',

		

		'type'=>'raw',

         	'value'=>"CHtml::dropDownList('listname', '', 

       		  

              array('1' => 'Cancel', '2' => 'Reassign','3'=>'Hold'),

              

              array('empty' => '(Action)','onchange'=>'js:alert($(this).val());',

              

              'ajax'=>array(                            

              'type' => 'GET',

              'url' => Yii::app()->createUrl('order/ChangAction',array('order_id'=>$model->order_id)),

              'data'=>'js:{clientId: $(this).val()}',                               

                                        )),

              array('class'=>'changeAcation')

                                        

              )",


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

		

        ),


	),

)); ?>



Try to use

‘order_id’=>$data->order_id

instead of

‘order_id’=>$model->order_id

$data is only available only when you are INSIDE CGridView. Also be careful with the quotes, so your mistake is:

Remove the double quotes and replace it by single quotes here:

array(

‘header’=>‘Action’,

‘type’=>‘raw’,

‘value’=>'CHtml::dropDownList <-- see i replaced it by single quote ONLY then $data is available for use…

In your case it’s easier to generate the dropdown cell in a method of the controller or the model. So you don’t have to care about the usage of " or ’ and no need for escaping apostroph…

See this article.

Thank all of you so much which effort to find solution.

Now It worked. i fixed as below:

[b]

Changed From:[/b]




'value'=>"CHtml::dropDownList('listname', '', 

                  

              array('1' => 'Cancel', '2' => 'Reassign','3'=>'Hold'),

              

              array('empty' => '(Action)','onchange'=>'js:alert($(this).val());',

              

              'ajax'=>array(                            

              'type' => 'GET',

              'url' => Yii::app()->createUrl('order/ChangAction',array('order_id'=>$model->order_id)),

              'data'=>'js:{clientId: $(this).val()}',                               

                                        )),

              array('class'=>'changeAcation')

                                        

              )"



[b]

To:[/b]




	'value'=>'CHtml::dropDownList($data->order_id, \'\',

       		  

         array(\'1\' => \'Cancel\', \'2\' => \'Reassign\',\'3\'=>\'Hold\'),

              

        array(\'empty\' => \'(Action)\',\'onchange\'=>\'js:alert($(this).val());\',

              

         "ajax"=>array(                            

           \'type\' => \'POST\',

           \'url\' => Yii::app()->urlManager->createUrl(\'order/ChangAction\'),

           \'data\'=>"js:{action_id: $(this).val(),order_id: $data->order_id}",                               

                                        )),

              array('class'=>'changeAcation')

                                        

              )'



right, the problem caused quotes.