Diego Guerrero
Diego Guerrero

Reputation: 33

yii2 gridview hide filter row conditionally

How i can hide "filter row and header of gridview" conditionally in yii2. I want show filter row of gridview in pc screen but hide in smartphone screen, also hide or show header of gridview based on the above conditions. it's this possible? Thanks

Upvotes: 1

Views: 2674

Answers (1)

arogachev
arogachev

Reputation: 33548

I see two possible options.

1) Use CSS and media queries, for example:

@media (min-width: 0px) and (max-width: 767px) {
    .filter {
        display: none;
    }
}

Using frameworks like Bootstrap 3 it's even easier, just add class hidden-xs (see more info in official docs)

This obviously just hides desired block from view, but it's still loaded and exists in the DOM.

2) If you don't want even generate HTML related with filter, you can use extensions like Mobile_Detect. It has Yii2 integration.

Example of usage:

<?php if (Yii::$app->devicedetect->isMobile()) { ?>
    <div class="filter">...</div>
<?php } ?>

Choose depending on your needs. Since you want also to hide GridView header, option 1 is better because otherwise you will possibly need subclass GridView widget.

Upvotes: 3

Related Questions