New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yiiGridView javascript event 'updated' #1313
Comments
It would be nice if all the javascript plugins had custom events ... |
Agree. It seems to be not complicated, just add $(this).trigger('update.yiiGridView'); |
I also need these grid events: afterAjaxUpdate and selectionChanged callbacks are good but it's not possible to configure them on js side! |
$.yiiGridView('option') is also good! protected function attachAjaxUpdateEvent()
{
$trigger = '$("#"+id).trigger("ajaxUpdate");';
//check if trigger already inserted by another column
if(strpos($this->grid->afterAjaxUpdate, $trigger) !== false) return;
//inserting trigger
if(strlen($this->grid->afterAjaxUpdate)) {
$orig = $this->grid->afterAjaxUpdate;
if(strpos($orig, 'js:')===0) $orig = substr($orig,3);
$orig = "\n($orig).apply(this, arguments);";
} else {
$orig = '';
}
$this->grid->afterAjaxUpdate = "js: function(id, data) {
$trigger $orig
}";
} |
//Agree. It seems to be not complicated, just add $(this).trigger('update.yiiGridView');// where and how to add this code?can you give me detailed example please ? |
@jackhad /**
* injects ajaxUpdate event into widget
*
* @param mixed $widget
*/
public static function attachAjaxUpdateEvent($widget)
{
$trigger = '$("#'.$widget->id.'").trigger("ajaxUpdate");';
//check if trigger already inserted by another column
if(strpos($widget->afterAjaxUpdate, $trigger) !== false) return;
//inserting trigger
if(strlen($widget->afterAjaxUpdate)) {
$orig = $widget->afterAjaxUpdate;
if(strpos($orig, 'js:')===0) $orig = substr($orig,3);
$orig = "\n($orig).apply(this, arguments);";
} else {
$orig = '';
}
$widget->afterAjaxUpdate = "js: function(id, data) {
$trigger $orig
}";
$widget->registerClientScript();
} You can put it in controller and call statically in view, e.g. $grid = $this->widget('CGridView', array(
'id' => 'mygrid',
...
));
$this->attachAjaxUpdateEvent($grid);
Yii::app()->getClientScript()->registerScript('ajax-update', '
$("#mygrid").on("ajaxUpdate", function() {
... //do whatever after ajax update
});
'); |
It would be nice if yiiGridView will trigger js event updated when it has been successfully updated via ajax.
Current afterAjaxUpdate is not enough in case of several different functions to be executed on grid update.
What do you think?
The text was updated successfully, but these errors were encountered: