Yii Framework Forum: CGridView doesn't update - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView doesn't update Need help with using CGridView update Rate Topic: -----

#1 User is offline   benjie 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 21-February 12

Posted 16 May 2012 - 01:10 AM

Hi,

I'm having some trouble when i update a CGridView using
$.fn.yiiGridView.update();
as a success parameter in an ajax call.

I'm working on a page where i have a CActiveForm and a CGridView. The CActiveForm is used to add entries to the CGridView, which should be updated via jquery whenever an entry is added.

Here's the script i use for submitting my form (updates the grid after submission):
	$('#division-submit').click(function(){
		$.ajax({
			type:'POST',
			url: '".Yii::app()->createUrl('division/create')."',
			data:$('#new-division-form').serialize(),		
			success: function(){
				$('#new-division-form')[0].reset();
				$('.new-form').hide();
				$.fn.yiiGridView.update('division-grid');
			}
		});
	});



Whenever it is called, the gridview does not reload. instead, it hangs with the loading gif and this shows up in the Chrome console:
Uncaught TypeError: Object function (a,c){var d=[],e=function(a,B){b=f.isFunction(B)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(B)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)b_(g,a[g],c,e);return d.join("&").replace(bC,"+")} has no method 'querystring'
methods.update


Any ideas? :)

Thanks!
-Benjie
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 16 May 2012 - 02:17 AM

This code is not in the gridview JS... can you try to debug the call to the gridview update?

Try first to add some JS instruction after the call to update and set there a breakpoint to see if the error happens inside the update or even later...
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 16 May 2012 - 04:04 AM

Hello.
Where have you put this JS code? There's something wrong with the url.
Are you sure it's in a PHP string, because it looks like you are concatenating a static string with a dynamic url?

Edit: I mean it's ok if your code is something like
some_php_code("
$('#division-submit').click(function(){
                $.ajax({
                        type:'POST',
                        url: '" . Yii::app()->createUrl('division/create') . "', // the concatenation happens here
                        data:$('#new-division-form').serialize(),               
                        success: function(){
                                $('#new-division-form')[0].reset();
                                $('.new-form').hide();
                                $.fn.yiiGridView.update('division-grid');
                        }
                });
        });
"); // end of your string wrapping function/method

0

#4 User is offline   CullenSUN 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 08-August 12

Posted 15 October 2012 - 10:27 PM

I got this error, because I included another latest jquery.min.js, guess corrupted with Yii's jquery
0

#5 User is offline   Mroz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 02-October 12

Posted 13 November 2012 - 04:06 PM

If you put something like this
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>


inside your layout then you use cgridview, it loads its own jQuery. jquery.min.js then mess up $.param and the whole cgridview does not work.

My solution is to put
public $loadJQuery=true
in the controller and
<?php 
    if ($this->loadJQuery)
        echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>';
?>

into the layout file

and set
$this->loadJQuery=false
in every action using cgridview
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 13 November 2012 - 04:15 PM

Mroz you can set Yii to not load jquery at all and load it yourself at all times... for this use the scriptMap property http://www.yiiframew...criptMap-detail
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   Wesseling 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 11-October 13

Posted 11 October 2013 - 06:47 AM

In my case the cause of the problem was a missing library called "jquery.ba-bbq.js". It was missing, because I disabled it manually in the scriptMap config directive.
Also if your webroot/assets directory is not writable, that script will not be loaded and the jquery.yiigridview.js will generate the error you showed above.
0

#8 User is offline   alsantos123 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 02-November 13

Posted 02 November 2013 - 09:59 PM

View PostCullenSUN, on 15 October 2012 - 10:27 PM, said:

I got this error, because I included another latest jquery.min.js, guess corrupted with Yii's jquery



Thanks a lot, it was my error;
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users