Row id in CGridView

Hi,

I see only rowCssClassExpression 'in CGridView) which is intended, as far as I understood, to create new css class for each row.

But what I would like is to create a Css "id" for each row of the CGridView, which would encompass the keys of the data provided by the CActiveDataProvider

I think it would be very easy to achive this but I can’t … :huh:

Do you have some hints ?

Thanks

How about


$this -> widget('zii.widgets.grid.CGridView',array(

  'rowCssClassExpression' => '"myclass_{$data->Id}"',

));

? Not surem but maybe this will help.

Thanks Юрий Пюрбеев

I already thought about this solution, but I can’t imagine using a Css ‘class’ just for specifying a Css ‘id’

When I say “I can’t imagine”, I mean that when I use a such great framework as Yii, I imagine there is something provided for this stuff…

Api is so “huge” (it is not a complaint, or bad thing :D ) that I think I miss something about this Css “id”

But it would be a "correct" workaround anyway …

[font="Arial"]I would try the following:


$this->widget('zii.widgets.grid.CGridView', array

(

 	'id'=>'mygrid',

 	'dataProvider'=>$model->search(),

 	'filter'=>$model,

 	'columns'=>array

 	(

            'firstColumn',

            array

            (

                  'name'=>'bla',

                  'htmlOptions'=>array('id'=>'"col_'.$data->Id.'"'),

                  'value'=>'$data->Id',

            ),

 	),

));



With this you have your grid with the "firstColumn " which has the id "col_x.

With this you could easily find the row with jquery selectors:




$("col_x").parent(); // or something like that



Have not tested anything of the above code but hope it helps ;)

[/font]

Thanks you kokomo

But I think it would be easier.

I would like to ask development team whether this topic would be a "ticket improvment’.

I would be much more easier to have an id on each row of a CGridView.

I know there are a lot of workarounds, but it stays workarounds.

Of course it would be really simply if there is a rowCssIdExpression for example.

Can you explain why and how you will use this…

I don’t think this is good (eficient)… if there would be 1000 rows you would get 1000 css id’s…

rowCssClassExpression is not meant to create a new class for each row… it’s used to choose a class for the row depending on the result of the expression… for example odd/even or if you have a negative value to color that row in red… or something like that…

Problem is not to have 1000 rows. You repeat some code throughout those 1000 rows. Moreover you never display 1000 rows.

but paginate them.

When for instance you want to select a row by clicking on it, (not on a specific cell i mean) you may want to display a particular id to display in a view description of this article (based on the id)

In javascript you may want to retreive this Id. Much more efficient to retreive it directly from the id row.

I can imagine I’m wrong in my point of view and enought open minded to listen your explain and accept them …

I see your point… but as we follow standards… like the MVC… that define what goes where and what is used where…

CSS - class or id is used for presentation not for holding data…

I see …

Thanks

This will not work since htmlOptions cannot access $data object with column values.