Skip to content

Commit

Permalink
Fix #229: Ability to set readonly rows in EditableColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Feb 19, 2015
1 parent 91adff0 commit 78565f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGE.md
@@ -1,8 +1,9 @@
Version 3.0.1
=============
**Date:** 18-Feb-2015
**Date:** 19-Feb-2015

1. (enh kartik-v/yii2-dynagrid#47): Set a timeout for plugin reinitialization on pjax complete.
2. (enh #229): Ability to set readonly rows in EditableColumn.

Version 3.0.0
=============
Expand Down
23 changes: 22 additions & 1 deletion EditableColumn.php
Expand Up @@ -33,6 +33,7 @@ class EditableColumn extends DataColumn
* - $key mixed is the key associated with the data model
* - $index integer is the zero-based index of the data model among the models array returned by
* [[GridView::dataProvider]].
* - $widget EditableColumn is the editable column widget instance
*/
public $editableOptions = [];

Expand All @@ -41,6 +42,19 @@ class EditableColumn extends DataColumn
*/
public $refreshGrid = false;

/**
* @var boolean|Closure whether to prevent rendering the editable behavior
* and display a readonly data. You can also set this up as an anonymous function
* of the form `function($model, $key, $index, $widget)` that will return a boolean
* value, where:
* - $model mixed is the data model
* - $key mixed is the key associated with the data model
* - $index integer is the zero-based index of the data model among the models array
* returned by [[GridView::dataProvider]].
* - $widget EditableColumn is the editable column widget instance
*/
public $readonly = false;

/**
* @var array the computed editable options
*/
Expand Down Expand Up @@ -69,9 +83,16 @@ public function init()
*/
public function renderDataCellContent($model, $key, $index)
{
$readonly = $this->readonly;
if ($readonly instanceof Closure) {
$readonly = call_user_func($readonly, $model, $key, $index, $this);
}
if ($readonly === true) {
return parent::renderDataCellContent($model, $key, $index);
}
$this->_editableOptions = $this->editableOptions;
if (!empty($this->editableOptions) && $this->editableOptions instanceof Closure) {
$this->_editableOptions = call_user_func($this->editableOptions, $model, $key, $index);
$this->_editableOptions = call_user_func($this->editableOptions, $model, $key, $index, $this);
}
if (!is_array($this->_editableOptions)) {
$this->_editableOptions = [];
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -122,7 +122,7 @@ An enhanced data column that allows one to expand a grid row and display additio

## Editable Column (New)
### \kartik\grid\EditableColumn
An enhanced data column that allows you to edit the cell content using [kartik\editable\Editable](http://demos.krajee.com/editable) widget. Refer [documentation](http://demos.krajee.com/grid#editable-column) for details.
An enhanced data column that allows you to edit the cell content using [kartik\editable\Editable](http://demos.krajee.com/editable) widget. You can selectively choose to disable editable for certain rows or all rows. Refer [documentation](http://demos.krajee.com/grid#editable-column) for details.

## Formula Column (New)
### \kartik\grid\FormulaColumn
Expand Down

0 comments on commit 78565f9

Please sign in to comment.