Hi,
I figured out how to make an ajax call for CButtonColumn inside a CGridView, but now my problem is that, i can’t access the values of the CButtonColumn inside the success function of the ajax htmloption, this is what my CGridView looks like:
$this->widget('zii.widgets.grid.CGridView',
array('dataProvider' => $dataProvider,
'id'=>'select-grid',
'columns'=>array(
'name',
array(
'class'=>'CButtonColumn',
'template'=>'{add}',
'buttons'=>array(
'add'=>array(
'label'=>'Add Contact',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/email.png',
'url'=>'Yii::app()->createUrl("site/addContact", array("add"=>$data["person_id"]))',
'options'=>array( // this is the 'html' array but we specify the 'ajax' element
'id'=>'abutton', // this id is given to all the buttons in the CGridView
'ajax'=>array(
'type'=>'POST',
'url'=> "js:$(this).attr('href')", // ajax post will use 'url' specified above
'success'=>"function(data){
var excuse = $(this).attr('href'); // this is showing undefined
alert('Trial ' + excuse + ' And '+$(this).parent().parent().children(':first-child').text() );// this is showing undefined
}"
),
),
)
)
)
)
)
);
So how do we do that? How do i access the href of the button of a particular row?
i want to modify the href to become empty, and also modify the image src to ‘alreadyadded.png’, alt to Already Added
So, basically i want to update the values of the CButtonColumn (but row wise) through the success function, how do i do that?
As you will notice in the code
$(this).attr(‘href’);
$(this).parent().parent().children(’:first-child’).text()
are returning undefined.
Further, is there a way to assign different ids to the buttons? instead of the same id to all the buttons in the column?