can someone tell me how to display the $data in the button delete of the CGridview? i tryed to do that but i found that this is impossible because the "deleteconfirmation" zone is evalueted as a JS script not a PHP script. I explain my problem better :
this is my gridview :
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'esbilancio-grid',
'dataProvider'=>$dataProvider,
'emptyText' => 'Nessun contenuto',
'summaryText'=>'Totale {count} risultati',
'columns'=>array(
'anno_nome',
array(
'class'=>'CButtonColumn',
'template'=>'{update}{delete}',
'deleteButtonLabel' => 'Cancella',
'deleteConfirmation' => 'Attenzione: L\'eliminazione di anno [color="#FF0000"]$data->anno_name[/color] porterà i file abbinati a quell\'anno nella categoria generica "Archivio bilanci". L\'operazione non è reversibile. Desideri continuare?',
'updateButtonLabel' => 'Modifica',
),
),
));
The problem that the “‘deleteConfirmation’” is not evaluated as a php script so it doesn’t display the dynamic content.
How can i get the content of the $data in this case ?
if there is a better solution to display a confirm message containing the dynamic content i’ll be hppy to know it
i have tryed with editing a *my own button but it appear the same problem :
the configuration for additional buttons. Each array element specifies a single button which has the following format:
'buttonID' => array(
'label'=>'...', // text label of the button
'url'=>'...', // a PHP expression for generating the URL of the button
'imageUrl'=>'...', // image URL of the button. If not set or false, a text link is used
'options'=>array(...), // HTML options for the button tag
[color="#FF0000"]'click'=>'...', // a JS function to be invoked when the button is clicked[/color]
'visible'=>'...', // a PHP expression for determining whether the button is visible
)
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.
This is what manchened in documentation and in red (click) is where i’m supposed to put the “confirm(massage)” in JS, and in this attribute (click that i mean) all what is putted there is evaluated as a js not php.
my purpose is to display the $data in this confirm message.
I think it’s not possible with the “buttons”
is there and other class that make me do this ?
i dont want to use Clinkcolumn because i want that the delete request is done by ajax way (i mean refresh the gridview and not the hole page)
You can use jQuery to get the value of the first column to be displayed in the confirmation text…
this jQuery code will get the value of the first column: $(this).parent().parent().children(’:first-child’).text()
and you can use it like:
...
'deleteConfirmation'=>"js:'Attenzione: L\'eliminazione di anno '+$(this).parent().parent().children(':first-child').text()+' porterà i file abbinati a quellanno nella categoria generica \"Archivio bilanci\". L\'operazione non è reversibile. Desideri continuare?'",
...
NOTE: the "js:" at the beginning… and the proper use of double and single quotes…
I will only add that in this post you will find example, how to read contents of other column than first and use in in delete confirmation message box.
For the explanation of the “complex” jQuery read the comment #6 on this thread… you will see that this line works only for a click on a button in the CButtonColumn… as you are using selectionChanged… you don’t know where the user has clicked as he can click anywhere on the row…
I’m so perplexed that I forgot to explain about that .
Basically, I want to pass the content of the second column (in the selected row) to textfield in another window.
So, when user checks the checkbox, the ‘distributor id’ column content (of the selected row) will be passed to distributor id textfield in another window.
Wow! Looks very cool. Thanks a million for giving a detailed example, mdomba.
Edit: It works when page loads for the first time. Anyway, I notice that this event is not triggered after I do some filtering (search function) in CGridView. Any idea?