Click page in 2nd GridView pagination (**Problem here)
What happens when I try and change pages it shows the loading indefinitely, when I go to inspect and look at the network I see 2 request the first one type is pending then status cancelled, the 2nd one is a success but nothing on the GridView changes plus the loading icon stays. If I look at the response of the 2nd call it is all the correct output just not updating or changing the GridView.
Here is the Ajax action code to render the GridView:
public function actionRenderItemData() {
$data = $_REQUEST; // Handles POST from initial render and $_GET from page change
$criteria = Data::getData($data);
$dataProvider = new CActiveDataProvider(Data::model(), array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 20
)
));
$dataProvider->getPagination()->params = $data;
$this->renderPartial('_gridView', array(
'dataProvider' => $dataProvider,
'data' => $data
), false, true);
}
In the GridView I set the ajaxUrl passing the $_POST or $_GET data.
Yii::app()->createUrl('renderItemData', $data)
Any suggestions is much appreciated and thanks in advance.
New Issue:
I worked out the weird hang up / 2 calls by adding uniqId() to the id of the GridView since it is being re-rendered which fixed the mentioned issue. Now what I have is the GridView disappears completely there is a call and it is OK and the response is right but no updated GridView just disappears.
In case this is encountered by anyone else, it was because I was using YiiBooster TbExtendedGridView apparently there is a bug with the pagination it will throw a call stack error in the console. Switching to CGridView resolved the issue.
Not sure what your issue is exactly, I had to fix a lot of issue on a page with a lot of gridview in different tabs that are regenerated individually.
One thumb of rule is to assign a gridview id that you define (not one that is generated) in order to make sure that this id is always the same when the gridview is regenerated.
Here are two modfications that I apply to Yii when I upgrade the framework. I’ve reported these a long time ago, but for some reason that I do not agree with they are not integrated:
CButtonColumn:
To remove the 'on' event on a grid before setting it.
if(true) {
$class=preg_replace('/\s+/','.',$button['options']['class']);
$js[]="if(typeof(_gridf)==='undefined'){_gridf={};}"
."if(typeof(_gridf['on-{$this->grid->id}-{$class}'])!=='undefined') {jQuery(document).off('click','#{$this->grid->id} a.{$class}',_gridf['on-{$this->grid->id}-{$class}']);}"
."_gridf['on-{$this->grid->id}-{$class}']=$function;"
."jQuery(document).on('click','#{$this->grid->id} a.{$class}',_gridf['on-{$this->grid->id}-{$class}']);";
} else {
$class=preg_replace('/\s+/','.',$button['options']['class']);
$js[]="jQuery('#{$this->grid->id} a.{$class}').live('click',$function);";
}
jquery.yiigridview.js:
Add lines to switch off event listeners before defining them.
added: $(document).off('click.yiiGridView', '#' + id + ' .' + settings.tableClass + ' > tbody > tr');
original: $(document).on('click.yiiGridView', '#' + id + ' .' + settings.tableClass + ' > tbody > tr', function (e) {
added: $(document).off('click.yiiGridView', '#' + id + ' .select-on-check-all');
original: $(document).on('click.yiiGridView', '#' + id + ' .select-on-check-all', function () {
$(document).off('change.yiiGridView keydown.yiiGridView', settings.filterSelector);
$(document).on('change.yiiGridView keydown.yiiGridView', settings.filterSelector, function (event) {
-> There is a potential issue that there are other listeners using the same selector that might be deleted.
-> However, the risk is low because the selector is specific and likely to be used by the yiiGridView only.