Delete In Cgridview Not Working
Rate Topic:

I have a view that was created by Gii. As far as I understand, clicking the delete button in the grid should bring up a confirmation dialog and then send a POST request. However when I try it, I don't get a confirmation and a GET request is sent.

Do you have something like this in your HTML output?
If yes, then by using the developer's tool of your browser, you can set a break point in the first line of this function, and examine what's happening.
I guess the chances are, as Keith suggests, there's a javascript error in your code somewhere else other than this function.

I suppose that wouldn't get hit when clicking the button as it's just run once at the initial page setup, to attach the event.

Try writing your function in the same way as softark, as an anonymous function, rather than the serialized text that you've created. I imagine you could then set a break point within that function to determine if it was fired.

But the corrupt portion of the scripts should have been generated by Yii ... maybe by CGridView or CButtonColumn. The corruption should not happen usually.
I don't know what's happening.

Well that makes two of us then

Keith, on 04 October 2012 - 07:56 AM, said:

Try writing your function in the same way as softark, as an anonymous function, rather than the serialized text that you've created.

As softark said, the whole code is generated by Gii, didn't write any of it myself.

I'm using Yii 1.1.12 and the "Yii Bootstrap 1.0" extension. Don't think the later has any say in this though, the "bootstrap.widgets.TbGridView" and "zii.widgets.grid.CGridView" generate the exact same code (as posted above).

Any ideas on where to look for what's going wrong? Don't have a lot of experience with JS.

The line "$function=CJavaScript::encode($button['click']);" causes the "messed up" result. When I change it to "$function=$button['click'];", everything works like a charm with the delete buttons fully functional.

Ok this is embarrassing - for whatever reason my CJavaScript.php was still on Version 1.1.10, while all the other files had been updated to 1.1.12. Thus CButtonColumn used the CJavascriptExpression but that class was not recognised by CJavaScript.