Exemplo n.º 1
0
    /**
     * @param mixed $model
     * @param mixed $key
     * @param int $index
     *
     * @return string
     *
     * @throws Exception
     */
    protected function renderDataCellContent($model, $key, $index)
    {
        if ($this->checkboxOptions instanceof Closure) {
            $options = call_user_func($this->checkboxOptions, $model, $key, $index, $this);
        } else {
            $options = $this->checkboxOptions;
            if (!isset($options['value'])) {
                $options['value'] = is_array($key) ? Json::encode($key) : $key;
            }
        }
        $options['id'] = ArrayHelper::getValue($options, 'id', rtrim($this->name, '[]') . '-' . $key);
        return Checkbox::widget(['name' => $this->name, 'checked' => !empty($options['checked']), 'inputOptions' => $options, 'clientOptions' => ['fireOnInit' => true, 'onChange' => new JsExpression('function() {
                    var $parentCheckbox = $(".select-on-check-all").closest(".checkbox"),
                    $checkbox = $("#' . $this->grid->options['id'] . '").find("input[name=\'' . $this->name . '\']").closest(".checkbox"),
                    allChecked = true,
                    allUnchecked = true;

                    $checkbox.each(function() {
                        if ($(this).checkbox("is checked")) {
                            allUnchecked = false;
                        } else {
                            allChecked = false;
                        }
                    });

                    if(allChecked) {
                        $parentCheckbox.checkbox("set checked");
                    } else if(allUnchecked) {
                        $parentCheckbox.checkbox("set unchecked");
                    } else {
                        $parentCheckbox.checkbox("set indeterminate");
                    }
                }')]]);
    }
Exemplo n.º 2
0
 public function getDefaultItem()
 {
     return function ($index, $label, $name, $checked, $value) {
         $inputOptions = $this->inputOptions;
         $inputOptions['value'] = ArrayHelper::getValue($inputOptions, 'value', $value);
         return Html::tag('div', Checkbox::widget(['name' => $name, 'label' => $label, 'checked' => $checked, 'inputOptions' => $inputOptions, 'labelOptions' => $this->labelOptions]), ['class' => 'field']);
     };
 }
Exemplo n.º 3
0
 protected function renderDataCellContent($model, $key, $index)
 {
     if ($this->checkboxOptions instanceof Closure) {
         $options = call_user_func($this->checkboxOptions, $model, $key, $index, $this);
     } else {
         $options = $this->checkboxOptions;
         if (!isset($options['value'])) {
             $options['value'] = is_array($key) ? Json::encode($key) : $key;
         }
     }
     $options['id'] = ArrayHelper::getValue($options, 'id', rtrim($this->name, '[]') . '-' . $key);
     return Checkbox::widget(['name' => $this->name, 'checked' => !empty($options['checked']), 'inputOptions' => $options]);
 }
Exemplo n.º 4
0
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     $this->parts['{label}'] = '';
     $this->parts['{input}'] = Checkbox::widget(['class' => Checkbox::className(), 'model' => $this->model, 'attribute' => $this->attribute, 'options' => $options, 'label' => Html::activeLabel($this->model, $this->attribute, $this->labelOptions)]);
     return $this;
 }