Ajax: custom selectors

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!

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

Hi. You may want to see this thread: http://www.yiiframework.com/forum/index.php/topic/31206-how-get-row-from-cridview-button-click-event/

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:

2870

table.jpg

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

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 [font=“Courier New”]$.fn.yiiGridView.getSelection(‘some-grid’);[/font] 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).

Thank you bennouna,

you show me a new class "CClientScript"…

i will try to use it!

;)