Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbedair committed Apr 28, 2014
1 parent 09ff2ed commit 3d11861
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/widgets/TbEditableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();

Expand All @@ -111,7 +151,7 @@ protected function renderDataCellContent($row, $data)
'
);
$this->_isScriptRendered = true;
}
}
}

/**
Expand Down

0 comments on commit 3d11861

Please sign in to comment.