I suspect that CGridView access the $_GET array directly. You could include public attributes within the widget to allow overriding of the request parameter names, then just retrieve those parameters directly within the widget, such as:
Somewhere read that widget could be use like controller (widgets are kind of controller)
Another problem I found, widgets has no renderPartial since display a part of html
but how to manipulate it on ajax request?
I try that and works
public function actionTest() {
if (!Yii::app()->request->isAjaxRequest) {
$this->render('indexWithmyWidget');
} else {
$this->widget('mywidget');
}
}
//and in indexWithmyWidget.php
$this->widget('mywidget');
My widget take entire ajax response and replace the div region with new one, so if the response is the entire html all javascript on client side corrupted by duplicates javascript code (and html)
I don’t know how exactly works the CGridView ( I assume get a part of ajax response and replace the cgridview html with new one) but in my case I have to check whether is Ajax request.
If rendering is seperated according to type of the request then evertything works ok,
But I am curious how The CGridview works in this case
As far as I know, CGridView and CListView are fairly straightforward in the server side.
They don’t check if the request is an ajax or not. They just register the necessary scripts and render the content.
When they are rendered in render, the scripts will be output, but when they are rendered in renderPartial, the scripts will not be output. Calling render or renderPartial is up to the user. By checking if the request is an ajax, you may optimize the output by using renderPartial. Although, such a lazy programmer as I can still use render for the response to an ajax request, because in the client side they are clever enough to get only the necessary part from the whole response.
The following is from ‘jquery.yiigridview.js’ … from line 234 and on:
update: function (options) {
...
success: function (data) {
var $data = $('<div>' + data + '</div>');
$grid.removeClass(settings.loadingClass);
$.each(settings.ajaxUpdate, function (i, el) {
var updateId = '#' + el;
$(updateId).replaceWith($(updateId, $data));
});
The key point here is "$(updateId).replaceWith($(updateId, $data));" which usually replaces only the grid content with the counter part in the response.
You can update not only the grid itself but also some other elements in the page in a single ajax call, by specifying the extra elements in ‘ajaxUpdate’ property. This is sometimes very convenient. It could have been difficult to implement without the basic schema stated above.