kartik-v / yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.
http://demos.krajee.com/dynagrid
Other
74 stars 66 forks source link

Enhance dynagrid config form when all settings are hidden #180

Closed yanhuixie closed 6 years ago

yanhuixie commented 6 years ago

Prerequisites

Steps to reproduce the issue

  1. set the following properties to false
        'allowPageSetting' => false,
        'allowThemeSetting' => false,
        'allowFilterSetting' => false,
        'allowSortSetting' => false,
  2. refresh the page and set columns to hide/show via personalize dialog
  3. apply setting

Expected behavior and actual behavior

When I follow those steps, I see... there is no effect as expected hide/show setting

I was expecting... hide/show columns as set via personalize dialog

After some digging, we find out that if set "allowPageSetting allowThemeSetting allowFilterSetting allowSortSetting" at the same time, there will no any < input name="DynaGridConfig[xxx]" > element rendered into the form of personalize dialog, so L515 in DynaGrid.php "$this->_model->load(Yii::$app->request->post())" will return false and escape the following hide/show settins.

$this->_model = new DynaGridConfig(['moduleId' => $this->moduleId]);
$this->_isSubmit = !empty($_POST[$this->_requestSubmit]) && $this->_model->load(Yii::$app->request->post()) &&
    $this->_model->validate();

By the way, is "theme" necessary for this form? I also notice that a "required" validator is active for it in L92 DynaGridConfig.php.

['theme', 'required'],

Environment

Browsers

Operating System

Libraries

Isolating the problem

kartik-v commented 6 years ago

I am not sure if I can completely understand why you are facing an issue. But I can clarify a few things. The theme property is mandatory. If you set allowThemeSetting to false a hidden input will be rendered - which will ensure that a default value is always received.

So to summarize, the form submitted will always have at least one model attribute theme supplied via POST irrespective of the allowPageSetting, allowFilterSetting, allowSortSetting, allowThemeSetting values. If you can help what else is your app code and config to reproduce... this can be checked.

yanhuixie commented 6 years ago

Hi, @kartik-v , thanks for your reply. According to your reminder, we checked the config.php view, and maybe it's the answer. Let's see L75 of config.php, yes indeed it guarantees that at least "a hidden input will be rendered" will take effect. But I think it has a precondition, let's see L53, the $col must not equals 0. Our scenario is that we set four parameters to false at the same time, it means that $col will just equals 0, so eventually no field elements such as hidden input or textbox will be rendered and it causes the "$this->_model->load()" method failed at L515 in DynaGrid.php.

$cols = (int)$allowPageSetting + (int)$allowThemeSetting + (int)$allowFilterSetting + (int)$allowSortSetting;
$col = $cols == 0 ? 0 : 12 / $cols;

Hope this may help, thanks.

kartik-v commented 6 years ago

Ok ... thanks for the info... will check this.