Search code examples
phpyii2yii2-basic-app

How can i create a gridview with no data on loading?


So i have an standard gridview created by gii, it is connected to a mysql database that already have some records, it works perfect but i need that when the page is loaded, no data should be displayed on the view, it only should be displayed after a search is done on any of the fields.

How can i setup a gridview that on load no data is displayed?

Thanks in advance


Solution

  • You could do something like this (or a variation with several search parameters) in your ModelSearch.php

    if($this->your_search_attribute == '') $query->andFilterWhere(['id' => 0]);
    

    Do not know if there's a easier more yii-like way..