Yii Framework Forum: How To Update Cgridview With Javascript - Yii Framework Forum

Jump to content

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

How To Update Cgridview With Javascript Rate Topic: -----

#1 User is offline   Daniel Chen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 22-August 12

Posted 20 December 2012 - 11:20 PM

Hi All,

I got the problem about the cgridview is not reload when call method $.fn.yiiGridView.update('list_product');

Please help!

Below is the javascript and cgridview page...

<button class="btn" type="button" id="btn_product" value="Product">Product</button>

<?php
		$this->widget('bootstrap.widgets.TbGridView',array(		
				'type'=>'striped bordered condensed',
				'id'=>'list_product',
				'dataProvider' => $dataProvider,		
				...				
				'columns'=>array(
					array(
						'class' => 'CCheckBoxColumn',
						'id'=>'p_col_chkbox',
						'selectableRows' => '2',
						'header'=>'Selected'
					),						
					array(
						'name'=> '', 
						'header'=>'#',
						...	
					),														
					..
			));		
?>


<script>

$("button#btn_product").click(function(e){
	
	//prevent normal action of tag
	e.preventDefault();

	// Get selected items from cgridview - checkbox 
	checked_item_list = $('input[name=\"p_col_chkbox[]\"]:checked');
	
	var list_p_ids = new Array();
	for(i = 0; i < checked_item_list.length; i++)
	{
		list_p_ids[i] = checked_item_list[i].value;	
	}
	
	// Call ajax
	var request = $.ajax({		
		url: "<?= Yii::app()->controller->createUrl('updateProduct') ?>",		
		type: "POST",
		data: {theChkIds:list_p_ids}, 
		dataType: "text",

		success:function(data) {			
			// Update gridview
			$.fn.yiiGridView.update('list_product');			
	    },
	    error:function(data) {	    
	    	alert("failed");	    	
	    },	    			
	});
});
</script>


0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 20-April 11
  • Location:India

Posted 21 December 2012 - 12:07 AM

check with firebug in firefox.. see what happns in the console.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   Daniel Chen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 22-August 12

Posted 21 December 2012 - 02:45 AM

View PostRajith R, on 21 December 2012 - 12:07 AM, said:

check with firebug in firefox.. see what happns in the console.


Hi Rajith,

it's throw message: --
[14:31:01.785] TypeError: $.fn.yiiGridView is undefined @ http://localhost/spm...b/jquery.js:646

Thanks,
Daniel
0

#4 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 20-April 11
  • Location:India

Posted 21 December 2012 - 02:55 AM

View PostDaniel Chen, on 21 December 2012 - 02:45 AM, said:

Hi Rajith,

it's throw message: --
[14:31:01.785] TypeError: $.fn.yiiGridView is undefined @ http://localhost/spm...b/jquery.js:646

Thanks,
Daniel


ok.. so its jquery problem .

is it u registered it in layouts/main, or any repeat registration ?



or


normal gridview has $.fn.yiiGridView, i dnt knw about TbGridView . check it out.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#5 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 20-April 11
  • Location:India

Posted 21 December 2012 - 03:02 AM

comment unwanted jquery's... then try...
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#6 User is offline   Daniel Chen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 22-August 12

Posted 21 December 2012 - 04:05 AM

I don't register any Jquery in layout/main.

TbGridView is one of widget of Yii-boostrap. So I think $.fn.yiiGridView also works too.
0

#7 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 20-April 11
  • Location:India

Posted 21 December 2012 - 04:23 AM

View PostDaniel Chen, on 21 December 2012 - 04:05 AM, said:

I don't register any Jquery in layout/main.

TbGridView is one of widget of Yii-boostrap. So I think $.fn.yiiGridView also works too.




$(function() {

..

}

Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#8 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 20-April 11
  • Location:India

Posted 21 December 2012 - 04:29 AM

use this

in action.

<?php if (Yii::app()->request->isAjaxRequest){
Yii::app()->clientscript->scriptMap['jquery.js'] = false;
Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false;
Yii::app()->clientscript->scriptMap['jquery.yiigridview.js'] = false;
}


Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#9 User is offline   Daniel Chen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 22-August 12

Posted 23 December 2012 - 07:37 PM

View PostRajith R, on 21 December 2012 - 04:29 AM, said:

use this

in action.

<?php if (Yii::app()->request->isAjaxRequest){
Yii::app()->clientscript->scriptMap['jquery.js'] = false;
Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false;
Yii::app()->clientscript->scriptMap['jquery.yiigridview.js'] = false;
}




Hi Rajith,

It still doesn't work, on the console till throw '$.fn.yiiGridView is undefined".

I've changed another way to reload the cgridview by replace it with CJSON data like this:

$("#list_product").replaceWith(getData.content)


The getData.content is the cgridiew data

Thank you very much for your help.
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