From 3d11861ec301bb2d031f2de1131381b4a5471632 Mon Sep 17 00:00:00 2001 From: amrbedair Date: Mon, 28 Apr 2014 22:35:10 +0200 Subject: [PATCH] #526 --- src/widgets/TbEditableColumn.php | 44 ++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/widgets/TbEditableColumn.php b/src/widgets/TbEditableColumn.php index a6251edb..96f59f8e 100644 --- a/src/widgets/TbEditableColumn.php +++ b/src/widgets/TbEditableColumn.php @@ -44,11 +44,51 @@ public function init() } parent::init(); + + $this->registerScripts(); + //need to attach ajaxUpdate handler to refresh editables on pagination and sort //should be here, before render of grid js $this->attachAjaxUpdateEvent(); } + + /** + * try to register editable scripts before any render, this is used especially for empty data providers + * works only for CActiveDataProvider; reason is that we have to know model name + */ + protected function registerScripts() { + + if (!$this->grid->dataProvider instanceOf CActiveDataProvider) + return; + + /* dummy data */ + $data = new $this->grid->dataProvider->modelClass(); + $options = CMap::mergeArray( + $this->editable, + array( + 'model' => $data, + 'attribute' => $this->name, + 'parentid' => $this->grid->id, + ) + ); + + /* dummy widget */ + $widget = $this->grid->controller->createWidget('TbEditableField', $options); + + + $widget->registerAssets(); + + if (!$this->_isScriptRendered) { + $script = $widget->registerClientScript(false); + + //use parent() as grid is totally replaced by new content + Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->grid->id . '-event', ' + $("#' . $this->grid->id . '").parent().on("ajaxUpdate.yiiGridView", "#' . $this->grid->id . '", function() {' . $script . '}); + '); + $this->_isScriptRendered = true; + } + } /** *### .renderDataCellContent() @@ -95,7 +135,7 @@ protected function renderDataCellContent($row, $data) $widget->buildHtmlOptions(); $widget->buildJsOptions(); $widget->registerAssets(); - + //can't call run() as it registers clientScript $widget->renderLink(); @@ -111,7 +151,7 @@ protected function renderDataCellContent($row, $data) ' ); $this->_isScriptRendered = true; - } + } } /**