cgrid - custom button don't work after refresh

Hello guys,

I have a grid view with a custom button. The button code is this:




'update' => array(

							'url' => 'Yii::app()->createUrl("MyController/update/$data->id_macro_advert")',

							'visible' => 'true',

							'options' => array(

								'ajax' => array(

									'type' => 'POST',

									'url' => 'js:$(this).attr("href")',

									'update' => '#modBlock',

									'cache' => 'false'

								),

							),

						),



its function is to open a dialog box on the page.

When I load the page the first time the dialog appears. When you make a refresh button of the grid no longer opens the box. as a remedy?

anyone?

It probably won’t work because when you click on your custom button to update the grid, your custom button gets replaced by the new partial view, and so the javascript bound to it also disappears!

Try using clientChange in your button options instead.

thanks for the reply.

but I have two questions:

As ever with some grills work and others do not? considers that the code is

identical.

the code I use is this




'update' => array(

							'url' => 'Yii::app()->createUrl("Adt/update/$data->id_macro_advert")',

							'visible' => 'true',

							'options' => array(

                

								'ajax' => array(

									'type' => 'POST',

									'url' => 'js:$(this).attr("href")',

									'update' => '#modBlock',

									'cache' => 'false'

								),

							),

						)



As I enter the option that you said? the guide does not help me

No, I think I was wrong - according to the clientChange documentation what you’ve got there should be ok, since the ‘live’ option defaults to true.

I think you’ll have to look at the html source code for the generated page to see what is happening. Specifically look for the javascript that binds to the click event to see that everything is ok. If you don’t find it, post the generated html code here.

One thing, maybe - do you need to give each button a unique id for the live binding to work - I can’t see how a live binding can work without a selector that allows it to find the button when it is replaced.

Perhaps you would be better off just giving the button a class, without any ajax, then using delegate to bind to all buttons of that class after your widget (which is better jquery coding practice anyway).

Hello and sorry for the delay.

The delegate is already present

After inserting a new row in the grid, new row appears. when i press the button for edit items, the calling ajax don’t work.opens url in a normal way.

This is the javascript code that generates .

I’m going crazy :blink:




jQuery('#edc-header-grid').yiiGridView({'ajaxUpdate':['edc-header-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items','selectableRows':1,'pageVar':'EdcHeader_page'});

jQuery('body').undelegate('#yt0','click').delegate('#yt0','click',function(){jQuery.ajax({'type':'POST','url':$(this).attr("href"),'cache':'false','data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#modBlock").html(html)}});return false;});

jQuery('body').undelegate('#yt1','click').delegate('#yt1','click',function(){jQuery.ajax({'type':'POST','url':$(this).attr("href"),'cache':'false','data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#modBlock").html(html)}});return false;});

jQuery('body').undelegate('#yt2','click').delegate('#yt2','click',function(){jQuery.ajax({'type':'POST','url':$(this).attr("href"),'cache':'false','data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#modBlock").html(html)}});return false;});

jQuery('body').undelegate('#yt3','click').delegate('#yt3','click',function(){jQuery.ajax({'type':'POST','url':$(this).attr("href"),'cache':'false','data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#modBlock").html(html)}});return false;});

jQuery('body').undelegate('#yt4','click').delegate('#yt4','click',function(){jQuery.ajax({'type':'POST','url':$(this).attr("href"),'cache':'false','data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#modBlock").html(html)}});return false;});



Looking at that, I presume you have 5 items per page.

What do you mean by inserting a new row? How do you do that? If you’re doing it yourself using some javascript, then I would say that it’s normal that your button isn’t working, since it won’t have had the event handler assigned to it.

If you’re just changing pages through ajax and finding that the button then doesn’t work, you’ll need to look at the id assigned to the buttons (since you can see that is how it does the delegation).

In all cases, I still think you’d be better off not setting your javascript on a per button basis, but just adding a class and making a delegation for that class after your CGridView.

mmm …

I do not have five items per page. what I showed you the page’s source code after I inserted a row. it is also the newly inserted row. the row is inserted through the display of a dialog form which in turn makes an ajax call.

if I change the page using ajax and then pressed again the same button, it works.

Then suggest to create a js function to switch the task to make the ajax request if I understand correctly?

thanks

add information

after insert firebug notes this

setting is undefined jquery at 832

i found this

http://code.google.com/p/yii/source/detail?r=2882

but my version is newest

@version $Id: jquery.yiigridview.js 3191 2011-04-17 09:36:55Z alexander.makarow $

google chrome signs

Uncaught TypeError: Cannot read property ‘attributes’ of undefined

$.fn.yiiactiveform.validate:272

$.fn.yiiactiveform.each.validate

…error to post

anyone?

If jQuery is undefined after you use an ajax link on a GridView, I can only assume that there must be something wrong with your rendering parameters.

However, it’s very difficult to know without seeing code.

I suggest that either you follow through the debugging to find out why and at what stage jQuery is no longer defined, or post all your code here (action, view and model if you’ve customised anything).