Yii Framework Forum: Displaying model data in CGridView's delete button's confirmation - Yii Framework Forum

Jump to content

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

Displaying model data in CGridView's delete button's confirmation Rate Topic: -----

#1 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,193
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 15 December 2010 - 06:17 AM

Hi there,

I have two problems extending CButtonColumn and would appreciate any help as I found no solution in documentation. I've separated both problems into two topic as they are quite different and one post holding both of them become to long - no one would like to read it! :] Second problem has been described in this post.

I want to make delete button in CGridView behave exactly as delete menu item on view / update views generated by Gii for CRUD. But how to achieve this?

It is written in documentation that: "In the PHP expression for the 'url' option and/or 'visible' option, the variable $row refers to the current row number (zero-based), and $data refers to the data model for the row". Why the same isn't available for any other CButtonColumn property? For me, the easiest way would be to use code:

array
(
    	'class'=>'CButtonColumn',
    	'deleteConfirmation'=>'Do you really want to delete element with ID = !'.$data->ID."?"
),

Unfortunately this fails with "Undefined variable: data".

Then I tried:

'class'=>'CButtonColumn',
'template'=>'{delete}',
'buttons'=>array
(
	'delete' => array
	(
    	'label'=>'[-]',
    	'url'=>'"#"',
    	'linkOptions'=>array
    	(
        	'submit'=>array('delete', 'id'=>1),
        	'confirm'=>'Delete?'
    	)

	)
),

But this also is not working - default confirmation is show, probably because linkOptions is not an element of button configuration array!

And, again, if I change 1 at the end of submit to:

'submit'=>array('delete', 'id'=>$data->ID),
 'confirm'=>'Delete element ID = '.$data->ID.'?'

I got the same error, saying "Undefined variable: data".

I'm running out of ideas! :/

This post has been edited by Trejder: 15 December 2010 - 06:21 AM

Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,346
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 December 2010 - 06:38 AM

I too had this problem a while ago... the expression is not used for all properties probably because it would affect the speed of CGridView if it would be evaluated for all attributes...

to solve this you need to use jQuery and read the value from a column on the same row()

Check this thread and my solution to it - http://www.yiiframew...p?/topic/13804-
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 15 December 2010 - 06:42 AM

There has been a similar post not long ago, it seems that both 'buttons' and 'deleteConfirmation' are not evaluated but simply pasted.

That means that is not possible to use CButtonColumn for do that. You can use CDataColumn and passing lot of buttons like data, that will be evaluated and will work correctly.
0

#4 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,193
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 15 December 2010 - 07:35 AM

@mdomba: Thanks again for a wonderful and extremely fast solution. Of course, it works like a charm!

Since post, you pasted here contains solution not in English (Italian? Croatian?) I'll paste here English one example for future reference:

array
(
    	'class'=>'CButtonColumn',
    	'deleteConfirmation'=>"js:'Record with ID '+$(this).parent().parent().children(':first-child').text()+' will be deleted! Continue?'",
),

I will also add for others that we can also use jQuery's ntn-child function for retrieve contents of other column:

array
(
    	'class'=>'CButtonColumn',
    	'deleteConfirmation'=>"js:'Do you really want to delete record with ID '+$(this).parent().parent().children(':nth-child(2)').text()+'?'",
),


@zaccaria: Seems, mdomba proved it is possible with CButtonColumn, but thanks for your reply! :]
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
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