How To Update Cgridview With Javascript

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>




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/spmt/assets/6892f04b/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.

comment unwanted jquery’s… then try…

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() {


..


}



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.