Search code examples
yiicgridviewcbuttoncolumn

Yii CGridView and buttons


Looking to remove buttons based on data for that row.
Picture 1 - Normal with all buttons
To this where the second line has some data in the table that depicts something.
Picture 2 - With Button removed
I have seen how to color the rows which is nice but need to remove buttons as well. Any thoughts? (sorry for the external links, still a new user)


Solution

  • You can use your data to change visibility of the button columns like this:

    replace

    array(
      'class'=>'CButtonColumn',
    ),
    

    with something like this:

    array(
      'class'=>'CButtonColumn',
      'template'=>'{view}{update}{delete}',
      'buttons'=>array(
        'update'=>array(
            'visible'=>'$data->cust == "ST50"',
        ),  
      ),  
    ),  
    

    but it won't keep the spacing when the button is not visible. I'll leave that to you. You can customize other attributes of CButtoncolumn here's a couple of refs: here and here