yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

GridView with several CheckboxColumns and multiselect doesn't work #18090

Open hohnacker opened 4 years ago

hohnacker commented 4 years ago

What steps will reproduce the problem?

echo GridView::widget(
        [
            'dataProvider' => $yourDataProvider,
            'columns'      => [
                [
                    'class'  => CheckboxColumn::class,
                    'name'   => 'checkboxone',
                    'header' => Html::checkBox(
                        'checkboxone_all',
                        false,
                        [
                            'class' => 'select-on-check-all',
                            'label' => 'labelone'
                        ]
                    ),
                ],
                [
                    'class'  => CheckboxColumn::class,
                    'name'   => 'checkboxtwo',
                    'header' => Html::checkBox(
                        'checkboxtwo_all',
                        false,
                        [
                            'class' => 'select-on-check-all',
                            'label' => 'labeltwo',
                        ]
                    ),
                ],
            ]
        ]
    ); ?>

What is the expected result?

"Check all" functionality per Column Header

What do you get instead?

If I click on the first header checkbox no checkbox is checked automatically. The last columns work. It seems that always the last one wins.

image

I think the issue is in https://github.com/yiisoft/yii2/blob/master/framework/assets/yii.gridView.js #194 setSelectionColumn is called twice for each column. initEventHandler is called for both columns, but both with the same type name "checkAllRows". If we change checkAllRows with the column spezific name it would work.

Additional info

Q A
Yii version 2.0.35
PHP version 7.3
Windows 10
floor12 commented 4 years ago

I will check it today.

floor12 commented 4 years ago

Yes, this problem is confirmed by my experiments. The problem exists in yii.gridView.js file in initEventHandler function. This function and and structure gridEventHandlers object designed to store only one type of event for one grid view. Theoretically this can create other problems besides this problem with checkboxes. I already started work to fix this issue.

samdark commented 4 years ago

See https://github.com/yiisoft/yii2/pull/18103#issuecomment-645476633