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 filter/sort settings update for database storage #153

Closed lieszkol closed 7 years ago

lieszkol commented 7 years ago

When 'storage'=>'db' and user tries to edit existing sort/filter settings, the changes are simply not saved to the db. This is because of line 386 in DynaGridStore.php, function store(): $data = ($out != null) ? [$nameAttr => $this->name] : [ This should be changed to this so that if the key exists then it is updated: $data = ($out != null) ? [$nameAttr => $this->name, $dataAttr => $configData] : [

kartik-v commented 7 years ago

For UPDATE: Only name of the filter/sort can be changed and saved. For CREATE: The name of the filter/sort with entire detailed settings would be saved.

Therefore, if you need to actually edit the filter's or sort's detailed settings then the steps to follow is:

lieszkol commented 7 years ago

This seems counter intuitive from a user perspective. The help text on the popup dialog says: "Set a name to save the state of your current grid sort. You can alternatively select a saved sort from the list below to edit or delete." For me this means that I can edit an existing, saved setting. Ideally, whether the user is able to change existing filters should be a dynagrid setting. Otherwise it would be useful to make note of the above logic in the docs and the popup description should be changed to something along the lines of: "Set a name to save the state of your current grid sort. You can alternatively select a saved sort from the list below to edit the name or to delete."

I thought something was wrong on my end (why aren't the changes being saved!!!) which is why I spent time debugging it and creating this ticket for you :-) As a side-note, this feature would be way more useful if there would be a way to load a saved filter/sort other than setting it as a default in the grid config dialog. I.e. if there was a "Load" button on the filter/sort popup dialogs.

In any case thank you for all the work you've put into these widgets.

lieszkol commented 7 years ago

P.s. this is a bit inconsistent, since if the widget store is not db then filter/sort settings can in fact be updated, i.e. with the online dynagrid demo it IS possible to save changes to an existing filter/sort.

kartik-v commented 7 years ago

There is been some thought put into this on why this is such. Note that you need to consider all use cases of how users will be operating

  1. This way it is standard for users to only add filter settings by creating filters. Editing is just to edit the name of the filter.
  2. It thus allows users a method to rename and edit a filter name only. Typically this would be what one would want if you save a lot of filters -- you may just modify an existing filter name and if you need new settings then just create another filter (instead of trying to change settings for one).
  3. Let's consider user has 2 filters saved - red books, and books > 100
  4. To modify just red books to dark colored books he can just select red books and rename it... he does not need to worry if he has another filter criteria applied on his grid that will overwrite the filter logic settings.
  5. If he needs to create a filter (or edit a new filter to change its query settings) e.g. red books > 100, then he just selects this new criteria and creates a filter with name red books > 100 (or applies one of the presaved filters and does the changes). Then if he does not need red books he can delete red books.

Go through all use cases and if you have suggestions for improvement - you are free to submit a PR. Also consider the facts that this must not break the extension or usage if user has selected and applied filters inadvertently and tried to edit the filter name only.

kartik-v commented 7 years ago

this is a bit inconsistent, since if the widget store is not db then filter/sort settings can in fact be updated, i.e. with the online dynagrid demo it IS possible to save changes to an existing filter/sort.

Will need to check this and if it is not consistent will record an enhancement.

lieszkol commented 7 years ago

I would be happy to implement any changes if that would be helpful, but I wouldn't want to make any decisions regarding the workings of the widget.

kartik-v commented 7 years ago

A new property dbUpdateOnlyName is been added to DynaGrid. This defaults to false and is applicable only when storage is set to db. Saving the settings when this is false will save/update/overwrite both the filter / sort name and its settings. Setting this to true will only save the name on edits.

The hint text will be updated with better explanation of this setting.

For non database storage (session or cookie it will always save the name and also overwrite the settings).

lieszkol commented 7 years ago

Thank you for the support, works great!