0

I had a similar problem as afterAjaxUpdate callbackfunction CListView shows undefined.

Currently though my function isn't called. Really not sure why. Chrome shows no errors in the log.

I have the following in my HTML. And I can call it from the console log ok.

<script>
function savedUser()
{
    alert('hello');
}
</script>

And i'm using the following in my CGridView

'afterAjaxUpdate'=>'savedUser',

I feel that this is really obvious. But I've run out of ideas. Any help would be great

Community
  • 1
  • 1
Jonnny
  • 4,939
  • 11
  • 63
  • 93
  • 1
    I just made a try and it worked fine. Can you view source HTML and looking for something such as jQuery('#my_grid').yiiGridView( ... 'afterAjaxUpdate':savedUser}) to see whether it existed or not? – Telvin Nguyen Aug 18 '13 at 18:35
  • @TelvinNguyen Didn't get afterAjaxUpdate as expected. It is down as `'afterAjaxUpdate':function() {... ` That's just a series of statements like `jQuery('.popover').remove(); ` – Jonnny Aug 18 '13 at 18:39
  • 1
    'afterAjaxUpdate':savedUser should have to be there. I think it's important clue to indicate your problem. Just a guess, the grid which you are reviewing and the grid which has above setting are one? – Telvin Nguyen Aug 18 '13 at 18:46
  • @TelvinNguyen That was it! I have several grids and I have ways of moving items between grids and I had the function in the wrong place. Thanks Telvin – Jonnny Aug 18 '13 at 18:54

1 Answers1

1

You need to tell Yii that 'savedUser' is the name of a JavaScript identifier so that it does not encode it -- otherwise, Yii will place quotes around savedUser and JavaScript will treat it as a string instead of the name of a function.

You can do this by wrapping the name in a CJavaScriptExpression:

'afterAjaxUpdate'=> new CJavaScriptExpression('savedUser'),
Jon
  • 428,835
  • 81
  • 738
  • 806
  • Thank you for that. It doesn't seem to have fixed the problem though. Still nothing happens. – Jonnny Aug 18 '13 at 18:33
  • @Jonnny: That's strange. What does the browser's javascript console say? Any errors? – Jon Aug 18 '13 at 18:34
  • I thought so, no, no errors either. I just replied to @Telvin with his question. I know that in the docs afterAjaxUpdate expects `function(id, data) where 'id' refers to the ID of the grid view, 'data' the received ajax response data.`. But having seen the earlier Q on here I thought my way would be fine also. – Jonnny Aug 18 '13 at 18:41