2

I am using YiiBooster extension in yii.

I have created a form using 'booster.widgets.TbActiveForm', it works like a charm Now I just want to submit my form with ajax and update a grid

let's consider that

  • my form id = myform
  • my grid id = mygrid

I have the following code for the submit button in the form

       $this->widget(
                        'booster.widgets.TbButton',
                        array(
                            'context' => 'primary',
                            'label' => 'Add',
                            'buttonType' => 'ajaxSubmit',
                            'url' => Yii::app()->createUrl('myController/myAction',array('id'=>$model->deal_id)),
                            'ajaxOptions' => array(
                                'type' => 'POST'
                            )
                        )
                    );

the AJAX works like a charm, but where do I put the grid update code after the ajax call is returned to the client side?

$.fn.yiiGridView.update('mygrid');

I also check the TbButton api documentation but I could not find a solution.

My last resort would be to hook a jQuery click function with my submit button and make the AJAX call myself, but I am hoping for a better solution.

Flexo
  • 87,323
  • 22
  • 191
  • 272
  • @lin when you're editing posts please take the time to fix *all* the issues, not just a single, trivial one. – Flexo Oct 05 '14 at 22:45
  • @Flexo, I try it. I'am native. Because of this I dont correct spelling/gramma mistakes. ;) I hope you understand this. – lin Oct 06 '14 at 08:07

1 Answers1

4
$this->widget(
        'booster.widgets.TbButton',
        array(
            'context' => 'primary',
            'label' => 'Add',
            'buttonType' => 'ajaxSubmit',
            'url' => Yii::app()->createUrl(
                    'myController/myAction',array('id'=>$model->deal_id)
            ),
            'ajaxOptions' => array(
                'type' => 'POST',
                'success' => 'function(data) { 
                                $.fn.yiiGridView.update("mygrid");
                }',
            )
        )
);
Dinistro
  • 5,701
  • 1
  • 30
  • 38
Harutyun Abgaryan
  • 2,013
  • 1
  • 12
  • 15
  • well before reading i knew it wont work and i was right because the TbButton class does not have such index for ajaxOptions array. You can download the extension and see line no #343 - #348 on TbButton class ------ btw i tested it also didnt worked – Robert Loxy Oct 04 '14 at 15:08
  • aaaa in yiiboster not worked yhis optin use boostrap http://www.cniska.net/yii-bootstrap or write native ajax call – Harutyun Abgaryan Oct 04 '14 at 15:18
  • now i have developed the whole project on yiibooster cant change, but the point is if they provide option for ajaxSubmit how to get control of that - to me thats strange . – Robert Loxy Oct 04 '14 at 15:22
  • one minut i change answer try this – Harutyun Abgaryan Oct 04 '14 at 15:24
  • i know this will work i am using it know, btw your previous anwsere works i was using the wrong id for the grid :) thnx mate chng ans so that i can mark as helpful :) – Robert Loxy Oct 04 '14 at 15:31
  • hey the previous code was fine -- edit it so that i can mark it helpful – Robert Loxy Oct 04 '14 at 15:38
  • one more thing for error do i need to add error index ? – Robert Loxy Oct 04 '14 at 15:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62461/discussion-between-robert-loxy-and-harutyun-abgaryan). – Robert Loxy Oct 04 '14 at 15:41