0

How to set the grid's selected column value in lookup field as shown in image?

enter image description here

My view code,

  $this->widget('zii.widgets.grid.CGridView', array(
                'dataProvider' => AgentsModel::model()->search(),//searchByLogin(AgentsModel::model()->g_user_id),
                'id' => 'CGridViewUser',
            'selectionChanged'=>'
            function(id){
          id=$.fn.yiiGridView.getSelection(id);
          alert(id);
        }',

                'columns' => array(
                    'g_user_id',
                    'name',
                    'lastname',
                    'phone',
                    'mobile',
                  'email',
                ),
                'htmlOptions' => array(
                    'style'=>'cursor: pointer;',
                    ),                   

            ));

from above code im getting selected rowid,but dont know how to proceed further!!!

Ayyanar G
  • 1,545
  • 1
  • 11
  • 24
  • what is your exact need? Need to set data in textboxes when selecting row or doing search? – Kumar V Dec 23 '13 at 05:10
  • yes,have to set grid column "Name" value in textbox... – Ayyanar G Dec 23 '13 at 06:07
  • Are you using advanced search option? It will work when you are doing search with ajax. – Kumar V Dec 23 '13 at 06:22
  • No,here no search involved...just selecting the grid row should update the textbox with the value of grid column 'Name' that's all – Ayyanar G Dec 23 '13 at 06:36
  • Then you have to do with jquery with onclick event. In first answer, you just said "Yes" for both option. "Yes" for what? – Kumar V Dec 23 '13 at 06:40
  • on selecting row set value in textbox,can you give somw example code to get grid column value and setting in textfield? – Ayyanar G Dec 23 '13 at 06:49
  • check this SO url for more details: http://stackoverflow.com/questions/376081/how-to-get-a-table-cell-value-using-jquery – Kumar V Dec 23 '13 at 06:53
  • this is for table ,but i need it for cgridview can you provide some other extra informations to likw, 1) get particular column value from grid 2)setting that value in form textfield – Ayyanar G Dec 23 '13 at 08:09

1 Answers1

1

For your requirement, You have to assign some class name to each fields like cell1, cell2, cell3..etc.

Then try something like below:

$(".cell1").live("click",function(){

    $(".cell1_txt").val($(this).html());// cell1_txt is text class name. 

});

So each row can have class like cell1 for first cell, cell2 for 2ed cell .. etc.,

but textboxes must have class like cell1_txt, cell2_txt, cell3_txt.. etc.,

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Kumar V
  • 8,810
  • 9
  • 39
  • 58