Yii2: Gridview hide row on condition

Created on 5 May 2017  路  7Comments  路  Source: yiisoft/yii2

Why there is no visible property for row like in columns.
Ex:


 <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
       'rowVisible'=>true,
        'columns' => $gridColumns
    ]); ?>
question

All 7 comments

Why do you want to select a row and then not display it?

Thank you for your question.
In order for this issue tracker to be effective, it should only contain bug reports and feature requests.

We advise you to use our community driven resources:

If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now.

_This is an automated comment, triggered by adding the label question._

So why I want select column and hide it by visible property ? @samdark

I think the point is that you don't need to request that data row that you don't want to display.
This is request logic, it's not for GridView actually.

And there are difference between rows and columns. Column might represent calculated field, or might represent such field that needed inside AR (e.g. to make some calculations) but don't need to display for some user groups. It's pretty good applicate to column logic, and not so much for row.

For example: I have some goods, and they have some prime cost, but it's secret for customers, it's available only for managers and so on. But I also have some final cost, that depends on prime cost, that's why I need to require that cost too.
And if some customer mustn't see some goods (maybe, only for 18+? :) ), when it's better to request only suitable goods, because there is no sense to request other, they don't needed...

the main issue about this is pagination, if you hide some rows you would have different count of items on different pages, which is not good. Therefor visibility of rows needs to be decided on dataprovider or query level.

In some scenarios like in reporting its very difficult to query in Active Data Provider.In that kind of situation I made one function and called in grid view attribute.

So in this situation need to control rowVisible in gridview level.

@pptyasar that would put access control logic into the view, I would recommend to filter the results on model or controller level and use ArrayDataProvider to provide the result of that to the gridview.

Was this page helpful?
0 / 5 - 0 ratings