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?
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'",
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?
"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…
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.