Updating Record From Grid View Using Cjuidialog

I’m having problem displaying another form as cjuidialog box because with my current code, it will display a new window instead.

update button on cgridview




'update'=>array(

'imageUrl'=>$this->createImage("icons/edit.png"),

'options'=>array('style'=>'cursor:pointer;'),

'url'=>'CController::createUrl("/po/local/requestDetails/update", array("id"=>$data->id))',	

'click'=>'function( e ){updateItem($(this).attr(url)); $("#dlg-item").dialog( {"title" : "Edit Item"} ).dialog("open");}',)



javascript




function updateItem(e)

{

  e.preventDefault();

  <?php 

	echo CHtml::ajax(array(

	'url'=>array('//po/local/requestdetails/update/','request_number'=>$parentModel->request_number),

	'data'=> "js:$(this).serialize()",

	'type'=>'post',

	'dataType'=>'json',

	'success'=>"function(data)

	{

	   if (data.status == 'failure')

	   {

	        $('#dlg-item div.item-section').html(data.div);

		// Here is the trick: on submit-> once again this function!

	        $('#dlg-item div.item-section form').submit(addItem);

	    } else {

	        $('#dlg-item div.item-section').html(data.div);

	        setTimeout(\"$('#dlg-item').dialog('close') \",3000);

		$.fn.yiiGridView.update('item-grid');

	    }

	 }",

	))?>;

return false; 


}



Any help is greatly appreciated. Thanks.

First of all in your update button code, I’d make these two changes:




'update'=>array(

    'imageUrl'=>$this->createImage("icons/edit.png"),

    'options'=>array('style'=>'cursor:pointer;'),

    'url'=>'CController::createUrl("/po/local/requestDetails/update", array("id"=>$data->id))',     

    'click'=>'js:function( e ){

        updateItem($(this).attr("href")); // <- there’s no ‘url’ HTML attribute and you need the quotes

        $("#dlg-item").dialog( {"title" : "Edit Item"} ).dialog("open");

        e.preventDefault(); // <- add this

    }',

)



On the other hand I understand from the code that your updateItem js function manipulates the dlg-item node. So I think the dialog should be a callback of that function, or even included sequentially in the function.

Also try to debug your js (with Firebug for instance). I suspect many things not working.

the same code I am using when creating new item, and it works fine.

i debug it using firebug, the error is has no method ‘preventDefault’

I already updated those two changes you mentioned but same error still