mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 22:30:27 +08:00
Merge branch '9074-checkboxColumn-selectedRows-fix' of https://github.com/NekitoSP/yii2 into NekitoSP-9074-checkboxColumn-selectedRows-fix
This commit is contained in:
@ -143,7 +143,7 @@
|
||||
var $grid = $(this);
|
||||
var id = $(this).attr('id');
|
||||
gridData[id].selectionColumn = options.name;
|
||||
if (!options.multiple) {
|
||||
if (!options.multiple || !options.checkAll) {
|
||||
return;
|
||||
}
|
||||
var checkAll = "#" + id + " input[name='" + options.checkAll + "']";
|
||||
|
@ -81,6 +81,15 @@ class CheckboxColumn extends Column
|
||||
if (substr_compare($this->name, '[]', -2, 2)) {
|
||||
$this->name .= '[]';
|
||||
}
|
||||
|
||||
$name = $this->grid->showHeader ? $this->getHeaderCheckBoxName() : NULL;
|
||||
$id = $this->grid->options['id'];
|
||||
$options = json_encode([
|
||||
'name' => $this->name,
|
||||
'multiple' => $this->multiple,
|
||||
'checkAll' => $name,
|
||||
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
$this->grid->getView()->registerJs("jQuery('#$id').yiiGridView('setSelectionColumn', $options);");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,4 +142,13 @@ class CheckboxColumn extends Column
|
||||
|
||||
return Html::checkbox($this->name, !empty($options['checked']), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns header checkbox name
|
||||
* @return string header checkbox name
|
||||
*/
|
||||
private function getHeaderCheckBoxName()
|
||||
{
|
||||
return rtrim($this->name, '[]') . '_all';
|
||||
}
|
||||
}
|
||||
|
@ -272,6 +272,11 @@ class GridView extends BaseListView
|
||||
$this->filterRowOptions['id'] = $this->options['id'] . '-filters';
|
||||
}
|
||||
|
||||
$id = $this->options['id'];
|
||||
$options = Json::htmlEncode($this->getClientOptions());
|
||||
$view = $this->getView();
|
||||
$view->registerJs("jQuery('#$id').yiiGridView($options);");
|
||||
|
||||
$this->initColumns();
|
||||
}
|
||||
|
||||
@ -280,11 +285,9 @@ class GridView extends BaseListView
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$id = $this->options['id'];
|
||||
$options = Json::htmlEncode($this->getClientOptions());
|
||||
$view = $this->getView();
|
||||
GridViewAsset::register($view);
|
||||
$view->registerJs("jQuery('#$id').yiiGridView($options);");
|
||||
|
||||
parent::run();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user