Invisible rows in CGridView

Is there a way to make some CGridView’s rows invisible based on a condition?

Can you explain a bit more… why would you make some row invisible… and how would you use that…

You can filter all you need with the criteria before even rendering the grid…

Because I couldnt use condition with a column, it’s a computed one.

Only things that comes to mind is to use rowCssClassExpression and to set with CSS "display:hidden"… but note that this way the data is not displayed only on the page… but is seen in the page source…

How to use this rowCssClassExpression with an if condition?

I’m trying to find another ways to do what has been discussed on this post post

In your case would be

'rowCssClassExpression'=>'$data->points < 30 ? hiddenclass : normalclass'

but this solution is not good if you have sensitive data, as I wrote above… the data is still visible in the page source…

For example like that:

'rowCssClassExpression'=>'($row % 2 == 0) ? css_class_for_hidden_row : css_class_for_normal_row'

This should hide every second row, but only in viewport - not in a source code, as mdomba told you.

(Tip: not tested, just out of my mind, maybe has some errors)

EDIT: Oops! :] Seems, you were first, mdomba! :]

Agree with you. This can only be used for some supporting operation (maybe to pre-render, then hide some rows that eventually will be displayed with an AJAX call - as we were talking some days ago?). More sensitive data should be filtered out in a view (or even controller?) before sending it to CGridView (browser).

EDIT: It is also worth pointing out that this solution uses evil eval() therefore there might be some performance degradation (at least theoretically) and all the stuff related to using eval(), which is not a well-supported solution in PHP.

Another idea would be to use CListView… there a view file is executed for every row… and in the view file you can test for a condition and display data accordingly…

I got this error

Use of undefined constant hiddenclass - assumed 'hiddenclass'

hiddenclass should be under quotes… and this should be a class that you declare in your CSS…

Thx a lot! That’s working

// That’s why I like Yii