2amigos / yii2-grid-view-library

Highly enhanced GridView widget and grid components for Yii2
https://2amigos.us
Other
57 stars 16 forks source link

Using success callback in EditableColumn #19

Closed re1naldo closed 7 years ago

re1naldo commented 9 years ago

How to setup success callback for Editable when we use EditableColumn? I tried:

'class' => EditableColumn::className(),
    'attribute' => 'qty',
    'url' => ['arrangement/update'],    
    'editableOptions' => [
         'mode' => 'inline',
         'clientOptions' => [
               'success' => new JsExpression("function(response, newValue) {
                     // msg will be shown in editable form
                     if (response.status == 'error') {
                         return response.msg;
                     } else {
                          $('#arrangement-total-' + response.id).html(response.total);
                          $('#event-total').text(response.eventTotal);
                    }
              }")
        ]
   ]

but the success callback was not fired. I also tried without clientOptions and got the same result.

tonydspaniard commented 7 years ago

You need to set the clientEvents not clientOptions: https://github.com/2amigos/yii2-editable-widget/blob/master/src/Editable.php#L79

PS: Very sorry for the really, really late response.

gb5256 commented 5 years ago

I have the same issue. I do use ClientEvents, but the handler is not attached to the object. On the editable in a detail view, it does work as expected, but not on editableColumn. Does anybody have a working example?

  echo GridView::widget([
                    'dataProvider' => $model,
                    'summary' => '',
                    'columns' => [
                        [
                            'class' => EditableColumn::className(),
                            'attribute' => 'field_id',
                            'value' => 'field.name',
                            'url' => 'import-parser/editable', // the route to the editable action!
                            'type' => 'text',
                            'editableOptions' => [
                                    'mode' => 'inline',
                                    'value' => 'field.name',,
                                    'clientEvents' => [
                                        'save' => new \yii\web\JsExpression('function(response, newValue) {
                                                    alert("asdf");
                                          }')
                                    ]
                                ]

                        ] ... //other columns to follow here....
gb5256 commented 5 years ago

@tonydspaniard I have just checked your source and it looks like the clientOptions are ignored. I made a hack of it:

  1. Declaring public $clientEvents = null;
  2. Adding this into registerClientScript:

    if (!empty($this->clientEvents)) {
        $js = [];
        foreach ($this->clientEvents as $event => $handler) {
            $js[] = "jQuery('$selector').on('$event', $handler);";
        }
        $view->registerJs(implode("\n", $js));
    }

So I have chosen to make ClientEvent separate from EditableOptions, because this makes it more consistent with how the editableWidget of you is working. There you have clientOptions and clientEvents separated as well. I have tested it and it works for me. Please let me know what you think of it.

Thanks again for all your extensions ! gb5256