Yii Framework Forum: dynamic "deleteconfirmation" in the CButtonColumn ? - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

dynamic "deleteconfirmation" in the CButtonColumn ? Rate Topic: -----

#21 User is offline   rei 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 329
  • Joined: 10-November 10

Posted 28 December 2010 - 12:07 PM

Works perfectly with 'live'. Thank you.
Fipick - Find and pick recommendations
0

#22 User is offline   BillyRayPreachersSon 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 22-February 11

Posted 22 February 2011 - 01:49 PM

Instead of multiple calls to parent(), you can also make a single call to parents(), passing 'tr' as the selector, so instead of this, which would take the text from the 4th column of the table (the :eq selector uses 0-based numbering):

'deleteConfirmation'=>"js:'Are you sure you want to delete the user ' +
	$(this).parent().parent().children(':eq(3)').text() +
	'? This operation cannot be undone.\\n\\nPress \"OK\" to delete, or \"Cancel\" to abort without deleting.\\n\\n'",


You could use this:

'deleteConfirmation'=>"js:'Are you sure you want to delete the user ' +
	$(this).parents('tr').children(':eq(3)').text() +
	'? This operation cannot be undone.\\n\\nPress \"OK\" to delete, or \"Cancel\" to abort without deleting.\\n\\n'",


Dan
0

#23 User is offline   Trejder 

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

Posted 15 March 2011 - 02:37 AM

View Postmdomba, on 28 December 2010 - 10:55 AM, said:

It's becasue after an ajax call (sort/pagination/filtering) the gridview/listview gets reloaded..

Will it also be problem, if all AJAX calls of CGridView (sorting, pagination) will be changed to normal POST calls?

I mean - is it truly only a problem of reloading CGridView after AJAX call or maybe this little trick interference somehow, how CGridView works at all?
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#24 User is offline   Maurizio Domba Cerin 

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

Posted 15 March 2011 - 02:49 AM

"problem" is only on ajax calls... becasue the ajax call loads a completely new grid and replaces the current one...

if you use POST or GET (without ajax)... then a completely new page is loaded... new jQuery events are rendered/attached and all is working

but if you use ajax... the new page/sort/whatever is returned from the ajax call... and with jQuery the current page grid is replaced by the returned grid... so everything on the current page remains as is... only the grid is replaced... no new events are binded or new jQuery code is rendered... there is only the old one...

if you use the classic jQuery.click(...) method... it does work only on the original grid... that's why it does not work after that original grid is replaced by a new one...
but as per jQuery documentation... live() and delegate() works even for future elements... so if you use live()... it will work even after the grid has being replaced by a new one...

I hope it's more clear now...

if not... there is no other way then get your hands a bit dirty with jQuery... without Yii... just HTML and jQuery... and experiment a bit... read some books on it...
Find more about me.... btw. Do you know your WAN IP?
0

#25 User is offline   zaccaria 

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

Posted 15 March 2011 - 05:33 AM

Quote

if not... there is no other way then get your hands a bit dirty with jQuery... without Yii... just HTML and jQuery... and experiment a bit... read some books on it.


Well, said like that sounds a bit rough, but I quote Mdomba 100%.

Anyone should understand that zii widget are just widget for your confort, are not the solution of all problems. The fact that Yii supplies powerfull widget does't mean that is possible to run a site with lot of nice 2.0 stuff without knowing jquery.

Yii is a php framework, all ajax cute feature are just a plus, if some jquery feature is not available in Yii is not a Yii bug.
1

#26 User is offline   Jerry Wham 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 22-May 11

Posted 04 June 2011 - 06:17 PM

Just a complement :
For translating delete message in deleteConfirmation property, you have simply to use a php variable that you put in the js string.

Because the string is evaluated by js, it is not possible to use the "t" function. So, in using it in a php variable, the translation is done first, and then put in the js string.

For example :
$del = Yii::t('app','Are you sure you want to delete the user ');

$this->widget('zii.widgets.grid.CGridView', array(
		'dataProvider'=> $search,
		'filter'=> $model, 
		'filterPosition' => 'header',
		'columns'=>array( 
			array(
				'class'=>'CButtonColumn',
				'template'=>'{delete}',
				'deleteConfirmation'=> "js:'".$del."'+$(this).parents('tr').children(':nth-child(2)').text()+' ?'"
			),
   		......and so on

0

#27 User is offline   sonam 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 10-September 11

Posted 14 October 2011 - 06:40 AM

but what if first column we have taken is not id column how can we acheive the passing of id to js function....................is there any another way
0

#28 User is offline   Maurizio Domba Cerin 

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

Posted 14 October 2011 - 06:51 AM

There are few possibilities:

If it's in some other column.. you can read it from there...

If the ID is not in your columns (any column) and selectableRows is 1... you can use $.fn.yiiGridView.getSelection() to get the key value of the selected row..

and one possible solution is to have a hidden column with the ID values...
Find more about me.... btw. Do you know your WAN IP?
0

#29 User is offline   jowen 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 191
  • Joined: 13-July 11
  • Location:Malaysia

Posted 24 October 2011 - 09:39 PM

Hi mdomba and others,

Is there a way to render another pages when user click the delete button?? From that pages, user only can delete the record. Thanks..

This is to allow the user to make sure the record is the exact record to delete. Thanks again.
0

#30 User is offline   Maurizio Domba Cerin 

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

Posted 25 October 2011 - 02:03 AM

Check this extension - http://www.yiiframew...n/eupdatedialog
Find more about me.... btw. Do you know your WAN IP?
0

#31 User is offline   jowen 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 191
  • Joined: 13-July 11
  • Location:Malaysia

Posted 18 November 2011 - 04:08 AM

Hi mdomba and others,

Is there a way to render view page when user click the certain row in CGridView???

$this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'detail_view',
        'selectableRows' => '1',
        'dataProvider' => $dataProvider,
        'columns' => array(
            array(
                'class' => 'CCheckBoxColumn',  
            ),
          array(
                'name' => 'id',
            ),
            array(
                'name' => 'machine_tag',
            ),
            array(
                'name' => 'company_name',
            ),
            array(
                'class' => 'CButtonColumn', 
                'deleteConfirmation' => "js:'Record with ID '+$(this).parent().parent().children(':first-child').text()+' will be deleted! Continue?'", 
                ),
            ),

0

#32 User is offline   Trejder 

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

Posted 18 November 2011 - 05:13 AM

View Postjowen, on 18 November 2011 - 04:08 AM, said:

Is there a way to render view page when user click the certain row in CGridView???

Well, mdomba is actually a jQuery / JS guru here! :]

I would look around something like this (register new client script with following code):

$('.users-grid>table>tr').click(function({alert('Hi!')}));

(not tested, written from memory)

This should attach click event to every table row in table in div with ID = "users-grid" and you specify this id in your CGridView widget definition.

Instead of showing alert, as in the example, redirect to route (controller/action) you want to call, with parameters you need, and in this action, render a view, you want.

This will work for every table-row. But if you want to know, which exactly table row was clicked then... wait for mdomba's answer! :] I'm not that good and don't know how to do this.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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