Select box on CGridView and assign/update

Hi All,

I am having a customer table called tbl_customer where customer information resides and staff user table called tbl_user to manage customer data.

Model customer





public function attributeLabels()

        {

                return array(

                        'name' => 'Name',

                        'id' => 'ID',

                        'username' => 'username'

                        'password' => 'Password',

                        'email' => 'Email',

                        'lead_assigned_to' => 'Lead Assigned To',

                        'package' => 'Package',

                        'registration_date' => 'Registration Date',

                        'lead_remarks' => 'Lead Remarks',

                );

        }




Model user




public function attributeLabels()

        {

                return array(

                        'id' => 'ID',

                        'username' => 'Username',

                        'password' => 'Password',

                        'email' => 'Email',

                        'remarks' => 'Remarks',

                );

        }



Every day new customer gets register and that entry gets listed in alldata.php in cgridview.

in tbl_user there is admin user also who is have access to alldata.php and for other user’s

there is a page called mydata.php which will list the customer data in cgrid view assigned to the user by admin.

in alldata.php there will be dropdown menu which will list the user’s from tbl_user and a button called Assign.

admin user will select the data with the checkbox option and then select the user to whom he wants the data to assign and click on assign button.

After clicking on Assign button the selected data will be removed from the current page (alldata.php) and then gets listed in the mydata.php page of that selected user. Similarly it applies for the remaining data also.

I have managed to create a checkbox and dropdown list user on the alldata.php page by adding the below code in alldata.php




<?php $form=$this->beginWidget('CActiveForm'); ?>


        <div class="row"> 

        <?php echo $form->labelEx($model,'lead_assigned_to'); ?> 

        <?php echo $form->dropDownList($model,'lead_assigned_to', CHtml::listData(User::model()->findAll(), 'username', 'username'), array('empty'=>'Please Select'));?> 

        <?php echo $form->error($model,'lead_assigned_to'); ?> 

    </div>


......


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

        'id'=>'customer-grid',

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

        'filter'=>$model,




        'columns'=>array(


                  array( 

                        'class'=>'CCheckBoxColumn', 

                        'selectableRows'=>2 //allows to check multiple rows. 

                ), 



Can anyone please help me in getting the below things done.

admin user will select the data with the checkbox option and then select the user to whom he wants the data to assign and click on assign button.

After clicking on Assign button the selected data will be removed from the current page (alldata.php) and then gets listed in the mydata.php page of that user. Similarly it applies for the remaining data also.

Thanks in advance

hi

see this link

My link

Thanks for your quick response.

I am new to Yii and still learning. Will you please help me with the code so that i can give it a try.

Thanks in advance

in view :

drop down List :




 echo CHtml::dropDownList('newStatus', 0,CHtml::listData(User::model()->findAll(), 'username', 'username'),array('prompt'=>'Please Select' ));



ajax link for drop down :




echo CHtml::ajaxLink("edit", $this->createUrl('customer/getvalue'), array(

        "type" => "post",

        "data" => 'js:{theIds : $.fn.yiiGridView.getChecked("customer-grid","selectedIds").toString(),"status":$("#newStatus").val()}',

        "success" => 'js:function(data){ $.fn.yiiGridView.update("customer-grid")  }' ))

        );



gridview :




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

        'id' => 'customer-grid',

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

 

        'columns'=> array(

            array(

                'name' => 'check',

                'id' => 'selectedIds',

                'value' => '$data->customer_id',

                'class' => 'CCheckBoxColumn',

                'selectableRows' => '100',

 

            ),

            ....


 

 

        )

    ));



now you have a grid view that can select one or multi row and select Desired username .

in action controller , assign customer to user!

ok??

Hi,

Thanks for your help. I am sorry to say will you please also update the action controller.

I have updated the code as below. I don’t know whether adding the code under c-active form will work or not.

code in view.




<?php $form=$this->beginWidget('CActiveForm'); ?> 

 

	<div class="row" align='left'> 

        <?php echo $form->labelEx($model,'Assign Data To User'); ?> 

		<?php  echo CHtml::dropDownList('newStatus', 0,CHtml::listData(User::model()->findAll(), 'username', 'username'),array('prompt'=>'Please Select' )); ?>

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

    </div>

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


<?php

echo CHtml::ajaxLink("edit", $this->createUrl('customer/getvalue'), array(

        "type" => "post",

        "data" => 'js:{theIds : $.fn.yiiGridView.getChecked("customer-grid","selectedIds").toString(),"status":$("#newStatus").val()}',

        "success" => 'js:function(data){ $.fn.yiiGridView.update("customer-grid")  }' ),

		

		array(

        'class' => 'btn btn-info'

        )

        );

?>






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

        'id' => 'customer-grid',

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

 

        'columns'=> array(

            array(

                'name' => 'check',

                'id' => 'selectedIds',

                'value' => '$data->id',

                'class' => 'CCheckBoxColumn',

                'selectableRows' => '100',

 

            ),

            ....


 

 

        )

    ));



in customer controller :




public function actionGetvalue(){

$customerId = $_POST['theIds'];

}



Hi,

I have done as per your suggestion but after clicking on submit button nothing is happening.

Thanks in advance

HI,

Can someone please help me with the Action controller code as clicking on submit nothing is happening.

Thanks in advance…

Can someone guide me please…