Yii Framework Forum: Ajax: custom selectors - Yii Framework Forum

Jump to content

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

Ajax: custom selectors Start a redirect by clicking on a table row Rate Topic: -----

#1 User is offline   tune 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 27-March 12

Posted 21 May 2012 - 08:48 AM

hi all,
I state that know well the jquery/ajax fashion out from Yii-framework...

I show my need:
how can i do to start a redirect with ajax by clicking on a <tr> of a cGridView table?...so, is possible to customize the jQuery "selector" throught Yii framework?
...for example "$('tr_of_table').doSomething();" how can i identify "tr_of_table"?

i try to read many posts and material....but....i'm confusing about this aspect.
so....thanks in advance for your help!
0

#2 User is offline   jrn 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 03-October 11
  • Location:Los Angeles

Posted 21 May 2012 - 09:28 AM

If you need to have a unique identifier you could set an ID for the tr of the table like
<tr id="test">


Now you can use
$('#test').doSomething();
$("#test").css("border","3px solid red");


0

#3 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 21 May 2012 - 09:35 AM

Hi. You may want to see this thread: http://www.yiiframew...on-click-event/
0

#4 User is offline   tune 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 27-March 12

Posted 21 May 2012 - 10:16 AM

hi,
thanks about your reply,
but in my case I haven't the CButtonColumn object in my table...it's a simple table/row without the "view/edit/cancel" buttons,
as the image:
Attached File  table.jpg (258.43K)
Number of downloads: 3

mhm...
what i need is to translate this function to the YiiFramework standard,
but i'm encountering some problems to create it...
pure jQuery function:
$('row').click( //go redirect to controller "x" with the ID(of ticket) as data...to go to the detail view of the clicked ticket... );


...Thanks again ;)
0

#5 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 21 May 2012 - 06:21 PM

Well I hope this helps:
Yii::app()->clientScript->registerScript('customJS', "
$('table.items tbody tr').on('click', function(e) {
    rowIndex = $('table.items tbody tr').index($(this));
    $.ajax({
        'type': 'POST',
        'url': " . CController::createUrl("controller/action") . ",
        'cache': false,
        'data': 'clickedRow=' + rowIndex,
        'success': function(data){
            …
        },
        'error': function(){
            …
        }
    });
});
");


It's a quite standard Ajax template. You have also $.fn.yiiGridView.getSelection('some-grid'); that can return the row(s) that are selected when you have a CCheckboxColumn in your grid.

Now you say you want to redirect, so it looks like Ajax is not the ideal solution, is it? Maybe a modal dialog for the detailed view (you'll find nice tutorials for that), or a simple link (like the ones in CButtonColumn).
0

#6 User is offline   tune 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 27-March 12

Posted 22 May 2012 - 04:29 AM

Thank you bennouna,
you show me a new class "CClientScript"....
i will try to use it!

;)
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