free-jqgrid / jqGrid

jQuery grid plugin
https://github.com/free-jqgrid/jqGrid
Other
480 stars 195 forks source link

Addin column via columnChooser with groupHeaders #111

Open zoltan-fedor opened 9 years ago

zoltan-fedor commented 9 years ago

Hi, I would like to have a grid with both the groupheaders and columnChooser functionality. Unfortunately whenever I add a column via the columnChooser to the grid where the grid has groupheaders, the new column always gets added to the end of the grid and not to where I tried to add it to.

I understand that adding the column in the middle of two columns grouped together is not a good idea, but adding it outside of the groups should still be allowed (or at least I don't see a reason why it shouldn't).

Below is an example: http://broadcast-this.com/treegrid-4.9.0-groupheaders-columnchooser.php

After opening the above try to add the hidden "Quantity" column to the first position via the columnChooser and you will see that the "Quantity" column always lands in the last position. Without groupHeaders the "Quantity" field can be placed into the first position.

I assume this is a limitation of groupheaders. Would it be possible to allow placing as long as it is outside of grouped columns? (eg not placing it in the middle of a grouped column set, but between grouped column sets or in front / behind them) If the user was requesting to place the new column in the middle of a grouped set, then automatically place it behind the given grouped set.

Thanks

OlegKi commented 9 years ago

I can't solve the problem, because changing of columnChooser could be more complex. I ask you to hold the issue opened. I will come back probably later.

What I can suggest you is small workaround which can good work in some scenarios. Look at the showHideColumnMenu plugin (see the demo where one should open context menu on the column header) described in the answer. The plugin showHideColumnMenu can't change the order of the column. It can only hide/show some columns. It could be advantage in some scenarios. With respect of showHideColumnMenu the user can show hidden column without changing its original order. In the way the column could be displayed inside of correct group on the correct place. It could be good in some scenarios.

zoltan-fedor commented 9 years ago

Thanks Oleg! Yes, the workaround can help in certain scenarios, but unfortunately not in mine. I have dozens of "optional" columns for the users to display, having them in a fixed position wouldn't help them much.

Anyhow, I would appreciate if we could keep this issue open and you could come back to it at some point.

How I would see this working would not require a change in the GUI of the columnChooser (although a change in the GUI of the columnChooser to reflect the grouped column would be nice). I would be happy just with the enforcement of the "grouping" rules to happen in the background when the new column is placed into the display via the columnChooser. Currently, the new column is always placed to the last position (if there are grouped columns), instead of which I would prefer if it would be placed: a. into the position where it was requested, if that position is not in the "middle" of some grouped column b. if the requested position is in the "middle" of some grouped columns, then place the column right behind this group

In any case, I appreciate our support and I'm looking forward to this issue to be resolved at a later time.

Thanks!

OlegKi commented 9 years ago

The problem is in the common organization of the code of columnChooser. It fills two <select>'s (displayed columns and hidden columns) and uses existing ui.multiselect.js plugin. So one have now practically no control over the doing. ui.multiselect.js plugin allows just click on "+" or "-" buttons or to make drag and drop between two lists and allows to reorder the items with visible columns via drag and drop too. It uses jQuery UI sortable and jQuery UI draggable. To implement your requirements one need to make more deep changes of foreign code of ui.multiselect.js plugin and include some logic inside which changes the behavior of dragging and dropping. The current code of columnChooser just fills two <select>'s and then get the results after all will be done. What you need required definitively more deep changing the code of ui.multiselect.js plugin.

zoltan-fedor commented 9 years ago

Thanks, I don't want to argue, but I don't see why it would require change in the ui.multiselect.js, as I would not change how the columnChooser works, just how the new column order gets applied in jqGrid. Today, in the columnChooser whereever I add the new column it will always show up a the last column in jqGrid's grid if groupedcolumns are enabled. See adding the "Quantity" column in http://broadcast-this.com/treegrid-4.9.0-groupheaders-columnchooser.php

What I'm trying to say, that instead of always showing up as last, it should apply the above mentioned logic (see a. and b. options above). I assume the fact that it always show up last is not determined by the ui.multiselect.js, but in the jqGrid library, hence I think that the change would not affect ui.multiselect.js.

Obviously it would be a lot nice solution if ui.multiselect.js would be modified too to notify the user via some GUI methods that he cannot place a column there, because that would break up a groupedcolumn. This is the part you have mentioned above "include some logic inside which changes the behavior of dragging and dropping".

In either case, thank you very much for your continued support!

Luca7993 commented 8 years ago

Hi, I have updated the jquery.jqgrid.src for using columnchooser with groupheaders. My idea is to treat the grouped columns as a unique column, so in the column chooser I see only the first column where Group start (startColumnName) and not the Other columns in the Group. Before calling remapColumns, I change the perm collections adding the other grouped columns in the following position of first Grouped column. I hope you understand me because it's not simple for me to explain.

if you think it could be a good solution, I can try to make a pull request with all changes I've done

thank you for all your work!