Get Data Row Onclick Update Column

Hi

I have a CGridview, and I want to post the row data by ajax when I click the update button (CButtonColumn)

I implemented the ajax button but I can’t find an easy way to get the data of the correspoding row

Ho to do that?

Thanks

Hi please see this wiki

I hope it’s some help

In this wiki there is no something to get the data of the specific row ecxept the data id in the url

I search something to pass a serialized data of the row by javascript in the "data" parameter in the below code


 'ajax' => array(

      'type' => 'POST',

   	'url' => "js:$(this).attr('href')", // ajax post will use 'url' specified above

   	'data'=>//I search to put something here

Have you try this?


'data' => array('id' => 'js:this.value'),

unfortunately not works :(

So I think best solutions is you can create the onclick function on button it’s very simple and sweet.




 array(

                        'name' => 'Action',

                        'type' => 'raw',

                        'value' => ' CHtml::tag("div",  array("style"=>"float: left; margin:5px; cursor:pointer" ,"onclick"=>"updateartist({$data["id"]})","id" => "{$data["id"]}","href"=>"javascript:void(0);") ,

                                                    CHtml::tag("img", array( "src" => "' . Yii::app()->request->baseUrl . '/images/update.png"))

                                    ). CHtml::tag("div",  array("style"=>"float: left; margin:5px; cursor:pointer" ,"onclick"=>"deleteartist({$data["id"]})","id" => "{$data["id"]}","href"=>"javascript:void(0);") ,

                                                    CHtml::tag("img", array( "src" => "' . Yii::app()->request->baseUrl . '/images/delete.png"))

                                    )',

                        'htmlOptions' => array('width' => '55px'),

                    ),

Also please see this

I hope it’s some help

In the past I found a solution similar like that (or this ), passing all the fields to the ajax method, but it was enough complicated. Also, each time that I modified the cgridview columns I have to change javascript code (a lot of work, especially if you have mor columns),

I think I am very close to find A solution, If I find out I will post it! :)

In any case thanks!

I think you may try this

[size="2"]create the common button to all grid and call function like[/size]





 public static function getGridButtonAjax($formId, $gridId, $modelName, $options = array()) {

        $updateArray = array(

            'update' => array(

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

             		$.ajax({

				    	type: "GET",

				    	dataType: "json",

				    	data: $("#' . $formId . '").serialize(),

				    	url: $(this).attr(\'href\')+\'/ajax/' . $gridId . '\', 

				    	success: function(jsondata) {

					    	$.each(jsondata.attributes, function(key, value) {

						       // alert(key + value); 

						    	$(\'#' . $modelName . '_\'+key).val(value);

							});

			         	}

			         });

             		return false;

             	}'

        ));

        return $updateArray;

    }



I hope it’s some help

The solution was very short and dynamic!


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

;)

ok finally you solved them