1

I have a gridview(admin.php) of test table. Here, I have two colums Contact Approval and Greetings Approval. I need to put two radio buttons ('Contact' and 'Greetings')in admin page. When I click on 'Contact' radio button all the columns except for Greetings Approval should be displayed in gridview and When I click on 'Greetings' radio button all the columns except for Contact Approval should be displayed in gridview. The update.php should also have the same effect.i.e when I click on edit option the update.php should have the fields based on the radiobutton data.How can I do this. enter image description here

Below is the code of radiobuttonlist

    <div class="ContactGreetingGroup">        
<?php echo CHtml::radioButtonList('approval','',array('0'=>'Greetings Approval','1'=>'Contact Approval'),array(
    'labelOptions'=>array('style'=>'display:inline'),
    'onclick' => 'this.form.submit()', 
    'separator'=>''));     
?>
   </div>
Rudra
  • 711
  • 7
  • 13
  • 31

1 Answers1

1

CDataColumn has a 'visible' property. You just need to set it depending on your parameter.

$approval = Yii::app()->request->getParam('approval');

'columns'=>[
    [
       'name'    => 'greetings',
       'visible' => ($approval)? false : true,
    ],
    [
       'name'    => 'contact',
       'visible' => ($approval)? true : false,
    ],
],

As for changing the behavior of the edit button, (since you need a parameter to say if you want "contact-mode" or "greetings-mode") You must overwrite the view-buttons url property.

[
    'class'=>'CButtonColumn',
    'buttons'=>[
        'view' => [
            'url'=>'Yii::app()->createUrl(
                "Something/Update", 
                ["id"=>$data->id, "approval"->$approval ])',
        ],
    ],
],

After that you need to make a similar check in your update.php (_form.php) to decide what to display.

if( $approval ) :
....

Added:

If your radiobuttonlist is inside form-tags, you can submit it like this:

<form>  <!-- You need a form to use form.submit! -->
    <?php echo CHtml::radioButtonList('approval','',
        array('0'=>'Greetings Approval','1'=>'Contact Approval'),
        array('labelOptions'=>array('style'=>'display:inline'),
        'onclick' => 'this.form.submit()',   // Added this.
        'separator'=>'')
); ?>
</form>

I also edited the above code to match your variable names. I haven't tested it, but it should give you an idea I hope.

ippi
  • 9,857
  • 2
  • 39
  • 50
  • Thank you for ur reply...I used radiobuttonlist. Please tell me what should I do for this. – Rudra Aug 12 '13 at 06:55
  • Can you please suggest me how to do it with above attached radiobuttonlist code. – Rudra Aug 12 '13 at 07:11
  • This isn't working for radiobuttonlist done with the above code – Rudra Aug 12 '13 at 07:23
  • There is no action of radiobutton at all – Rudra Aug 12 '13 at 07:31
  • did you add the onclick? It MUST be inside
    tags to be submitted as a form. If you don't want the page-refresh, you should render it all inside a renderPartial but you ought to leave that for another question.
    – ippi Aug 12 '13 at 07:32
  • Yes...I got it.Now the radiobutton is working but it goes to a different page. Url-http://localhost/yii/test/index.php?approval=1. Nothing gets displayed – Rudra Aug 12 '13 at 07:43
  • Hello ippi, pls guide me on this – Rudra Aug 12 '13 at 07:52
  • controls where you are sent. Leaving it blank *should* return you to the same page. Maybe you have nested forms causing you end up somewhere else? – ippi Aug 12 '13 at 07:54
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/35253/discussion-between-ippi-and-rudra) – ippi Aug 12 '13 at 07:59