Yii2: CheckboxColumn 'multiple' property documentation and RadioColumn

Created on 24 Dec 2014  路  12Comments  路  Source: yiisoft/yii2

The problem is yii\grid\CheckboxColumn documentation states that 'multiple' property is used for 'whether it is possible to select multiple rows', but actually it adds checkbox, that allows to select ALL the rows. I wonder if there is something like RadioColumn, or possibility to restrict select several checkboxes (only 1 per column)

need more info to be verified

Most helpful comment

Instead of multiple, it could be "selectAll" to avoid confusion

All 12 comments

Isn't this the current behavior already? If multiple is false, the header cell won't display the select-all checkbox, and you can only toggle one checkbox at a time.

Nope, if multiple is false, then header won't display, but i can toggle several checkboxes. Also, i looked into js about this property, it has

setSelectionColumn: function (options) {
            var $grid = $(this);
            var id = $(this).prop('id');
            gridData[id].selectionColumn = options.name;
            if (!options.multiple) {
                return;
            }
           ...

so i guess its something like it leaves default behaviour of browser, which allows all checkboxes to be toggled...

Checkboxes are supposed to be multi-select. If you only want users to be able to select one out of several choices then you should use radio buttons instead.

Well, yeah, thats why I wonder:

  1. If there is something like RadioColumn (I know there is not)
  2. If statement 'possible to select multiple rows' is accurate. I think, that if I can't select multiple rows, it means I can select only one.... right?

I agree that the property name and description is a bit misleading, but checkboxes aren't naturally grouped like radio buttons are. You can create faux groups by placing the checkboxes close together and giving the bunch a single header, but they are all actually separate inputs. With "multiple" the checkboxes are in a way grouped together (via the "select all"-button) but there's nothing saying that you can't select multiple rows by yourself. And there shouldn't be. If you need that kind of constraint, then you should use radio buttons.

Ok, agreed, thanks and sorry for this thread.

You may want to refer this if it helps and the demo for details.

Hey, guys! Why this issue was closed? I have same problem! When multiple set to false you CAN select multiple checkboxes. I think this must be fixed somehow.

@yapi68 It was closed because it is not a real issue. If you need to make it so that you can't select multiple checkboxes, then you should really use radio buttons instead. That's what differs between the two. If you need to select multiple "options", then use checkboxes; If you need to select just one "option", then use radio buttons. The issue is in your design, not the framework.

It is an issue because doc says: "Whether it is possible to select multiple rows."
All this feature does is wasting time of users which try to figure out what they do wrong.
So either remove it or fix it.

Btw it worked fine in Yii 1. Another reason to make me regret I ever switched to Yii 2.

@asbator I agree that the naming of the variable and the phrasing of the description is off. This should be fixed. However, the issue is still in your design and not in the actual functionality of the helper function.

Instead of multiple, it could be "selectAll" to avoid confusion

Was this page helpful?
0 / 5 - 0 ratings