Yii Framework Forum: ajax and gridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

ajax and gridview Rate Topic: -----

#1 User is offline   karim gioca 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 21-September 10

Posted 01 November 2010 - 06:01 AM

hi everyone,

i want to put buttons in each row of the gridview that on click of each one it takes me to a controler action with and id of this specefic row , to do that i want on click of one of those buittons appears a costom confirm box (done by jquery) to do execute this action. but i don't know how to redirect to a controller action on clik of that confirm(this confirm use a jquery script to test the click(yes or no) this is the link to the jquery script if you want to know ).
this is my crgid view code (the part that contain the buton declaration) :

	array(
                 'class'=>'CButtonColumn',
                 'template'=>'{del}',
                 'buttons'=>array(
                          'del'=>array(
                                   'label'=>'attivare/desattivare',
								   
                                
                                   'click'=>'function() {
											
        
                jConfirm("Are you sure you want ot delete this thread?", "Confirmation Dialog", 
                function(r) {
                
                if(r==true)
                {
                  $.ajax({
		   type: "POST",
           url: "/easyspeed/index.php/essponsor/delete/11",
           success: function() { $("#sponsor-grid").yiiGridView.update("sponsor-grid"); },
           error: function() { alert("Ajax button failed"); }
                        });
                }
				});
                        }',
                                         ),
                        ),




the problem is in 2 parts :

1- the first part is how to pass each id in the ajax request(on click of corse).
2- the second is how to put the url that redirect to the action controller in the "url" parametter of "$.ajax()" ? the problem that the parametter "click" of the buttons attrebute avaluate a js script not a php script.i said that because i tryed to put Yii::app()->createUrl in the 'url' parametter of the ajax request but it is not evaluated.

wish you help me in this problem
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 01 November 2010 - 07:18 AM

As specified in the doc, you can use the variables $data and $row in the button expression:

'
[...]
 url: "'.CHtml::normalizeUrl('delete').'{\$data->id}"
[...]',


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users