|
|
|
@ -117,7 +117,24 @@ class DataColumn extends Column
|
|
|
|
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
|
|
|
|
*/ |
|
|
|
|
public $filterInputOptions = ['class' => 'form-control', 'id' => null]; |
|
|
|
|
/** |
|
|
|
|
* @var string the attribute name of the [[GridView::filterModel]] associated with this column. If not set, |
|
|
|
|
* will have the same value as [[attribute]]. |
|
|
|
|
* @since 2.0.41 |
|
|
|
|
*/ |
|
|
|
|
public $filterAttribute; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@inheritdoc} |
|
|
|
|
*/ |
|
|
|
|
public function init() |
|
|
|
|
{ |
|
|
|
|
parent::init(); |
|
|
|
|
if($this->filterAttribute === null) { |
|
|
|
|
$this->filterAttribute = $this->attribute; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@inheritdoc} |
|
|
|
@ -161,7 +178,7 @@ class DataColumn extends Column
|
|
|
|
|
$model = $modelClass::instance(); |
|
|
|
|
$label = $model->getAttributeLabel($this->attribute); |
|
|
|
|
} elseif ($this->grid->filterModel !== null && $this->grid->filterModel instanceof Model) { |
|
|
|
|
$label = $this->grid->filterModel->getAttributeLabel($this->attribute); |
|
|
|
|
$label = $this->grid->filterModel->getAttributeLabel($this->filterAttribute); |
|
|
|
|
} else { |
|
|
|
|
$models = $provider->getModels(); |
|
|
|
|
if (($model = reset($models)) instanceof Model) { |
|
|
|
@ -189,26 +206,26 @@ class DataColumn extends Column
|
|
|
|
|
|
|
|
|
|
$model = $this->grid->filterModel; |
|
|
|
|
|
|
|
|
|
if ($this->filter !== false && $model instanceof Model && $this->attribute !== null && $model->isAttributeActive($this->attribute)) { |
|
|
|
|
if ($model->hasErrors($this->attribute)) { |
|
|
|
|
if ($this->filter !== false && $model instanceof Model && $this->filterAttribute !== null && $model->isAttributeActive($this->filterAttribute)) { |
|
|
|
|
if ($model->hasErrors($this->filterAttribute)) { |
|
|
|
|
Html::addCssClass($this->filterOptions, 'has-error'); |
|
|
|
|
$error = ' ' . Html::error($model, $this->attribute, $this->grid->filterErrorOptions); |
|
|
|
|
$error = ' ' . Html::error($model, $this->filterAttribute, $this->grid->filterErrorOptions); |
|
|
|
|
} else { |
|
|
|
|
$error = ''; |
|
|
|
|
} |
|
|
|
|
if (is_array($this->filter)) { |
|
|
|
|
$options = array_merge(['prompt' => ''], $this->filterInputOptions); |
|
|
|
|
return Html::activeDropDownList($model, $this->attribute, $this->filter, $options) . $error; |
|
|
|
|
return Html::activeDropDownList($model, $this->filterAttribute, $this->filter, $options) . $error; |
|
|
|
|
} elseif ($this->format === 'boolean') { |
|
|
|
|
$options = array_merge(['prompt' => ''], $this->filterInputOptions); |
|
|
|
|
return Html::activeDropDownList($model, $this->attribute, [ |
|
|
|
|
return Html::activeDropDownList($model, $this->filterAttribute, [ |
|
|
|
|
1 => $this->grid->formatter->booleanFormat[1], |
|
|
|
|
0 => $this->grid->formatter->booleanFormat[0], |
|
|
|
|
], $options) . $error; |
|
|
|
|
} |
|
|
|
|
$options = array_merge(['maxlength' => true], $this->filterInputOptions); |
|
|
|
|
|
|
|
|
|
return Html::activeTextInput($model, $this->attribute, $options) . $error; |
|
|
|
|
return Html::activeTextInput($model, $this->filterAttribute, $options) . $error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return parent::renderFilterCellContent(); |
|
|
|
|