free-jqgrid / jqGrid

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

Populate search drop down (suggestion) #420

Closed aberel closed 6 years ago

aberel commented 6 years ago

Hi, this is a suggestion, not a in issue. I see every dropdown in advanced search popup is re-created every time you add a new rule. Source: https://raw.githubusercontent.com/free-jqgrid/jqGrid/master/js/jquery.jqgrid.src.js

// populate drop down with user provided column definitions for (i = 0; i < that.p.columns.length; i++) { .....} `

That loop is executed every time you click the button "+" to add new rule, FOR EACH RULE already added previously. I think it would be a better idea (or performance) to create the dropdown AT ONCE and store in memory, since the colModel si unique and cannot be modified after grid init. Then you could clone the $element (dropdown) and place it when user needs new rules, and set "selected" and other attributtes. This way, also we can access the pre-created dropdown object and alter it via jquery after the grid is loaded (maybe I would add new options, or delete or disable ones, in some cases). Now this is impossible since every serach dropdown is created on the fly every time.

Regards!

aberel commented 6 years ago

Have to clear: I see I can access the select element using the searchoptions.dataInit() function, so the last point of my question maybe dismissed. For the main suggestion, I have the option search.recreateForm=false, but this seems to be affect only the form, not the dropdown constructor,

OlegKi commented 6 years ago

Hi Aberel,

I'm not sure that I understand the issue correctly. First of all recreateForm: false is not exist (will be not processed) in searchoptions at all. The file jquery.jqgrid.src.js contains tree places with the code fragment, which you posted. I agree, that free jqGrid "recreates" the most controls of searching dialog. You can examine the file grid.filter.js to see the behavior.

Free jqGrid is the fork of jqGrid 4.7. I rewrote many parts of the old code, but I had never the goal to rewrite the whole code. The goal of the most changes are bug fixing, introducing of new features and performance improvements, but it's interesting to improve performance therein, where one really have a bottleneck. The module grid.filter.js don't operate with large number of elements. Rewriting of the code have to make some additional adjustment of the code of grid.formedit.js too (see searchGrid method). In other words one can rewrite about 1000 line of code. I try to hold maximal compatibility with old versions of jqGrid (4.x<=4.7). One have to debug new code carefully. And what one will have at the end? Probably improvements measured in milliseconds. Do you have enough time for such job with so few final advantages? I think that the investments will be too much for the resulting benefits. I see many other places, which could be improved with less time investments, but I can't enough time free from my main job and the time, which I need for my family.

Despite of everything written above any improvements from your side are welcome. Free jqGrid is open source product. You can, like anyone, post improvements in the code as pull requests. It's important only that you test very carefully your changes and make the changes transparent, so that I can review there and to see advantages of the changes. (I try don't break existing code after new changes.)

aberel commented 6 years ago

Oleg, thanks for reply. I agree with you that it may require too much time to rewrite that module, and maybe the benefits will not be important. That's because I cleared this is NOT an issue, but a suggestion or a question, Now I know thay you already considered this job and it's really a hard work. Also I agree that any imprevement must require careful tests, so it will not break anything.

About "recreateForm", I read it in Tony's jqgrid docs ( http://www.trirand.com/jqgridwiki/doku.php?id=wiki:singe_searching#options ) Single field searching > Options: "recreateForm | boolean | when set to true the form is recreated every time the search dialog is activated with the new options from colModel (if they are changed) Maybe I missunderstood the docs, maybe is deprecated, don't know... Ok, anyway I understand it has nothing to do with recreation of search dropdowns (selectLabel) By the way, I just discovered the dataInit() function which is useful to access the dropdown (and eventually modify them from jquery).

Thank you again. Regards.

OlegKi commented 6 years ago

Hi Aberel,

you are right about the documentation of old jqGrid, but the option will still not used even by old jqGrid. In general the option recreateForm is misunderstanding. It will be used by Edit/Add/View forms, but only for saving/restoring the width, height and position of the dialog forms. Look at the lines of code, which saves some parameters and here, where the parameters overwrite the parameters of editGridRow. It's all what recreateForm do. By the way, such saving/restoring can work incorrectly in case of complex structure of outer divs of jqGrid (for example, if some outer dives have relative and another absolute position).

If you look at the code of jqGrid 4.7 you will see that searchGrid don't use recreateForm at all. If you still use it in combination with form option then some properties of searching form can be saved, but never used. The method searchGrid has recreateFilter parameter, but it has another meaning (see the lines). In any way neither recreateForm nor recreateFilter can change the behavior of creating controls in the corresponding form.

About the documentation of free jqGrid. There exist only the page, the wiki and the file free-jqgrid.d.ts, which describes in TypeScript syntax all methods, options, parameters, callbacks and events. The file free-jqgrid.d.ts can be used by some text editors (like Visual Studio Code) for IntelliSense (syntax highlighting and autocomplete) (see here, for example). free-jqgrid.d.ts is currently the mostly full and exact documentation of free jqGrid. If you just look at the file you will see that it's written very compact and it's still over 2000 lines. Everybody can imagine the size of the corresponding more full documentation with much more text. The zeitnot is the reason, why there are not exist full documentation of free jqGrid.

Best regards

aberel commented 6 years ago

Oleg, thanks again. I use the freejqgrid 4.13 (not the old 4.x). I just frequently read the old wiki because the habit and full description, but you are right, I have to go to your current docs, since the old docs may deprecated for my version. Now my need is to solve the following (I posted in Stackoverflow which is more appropiate for questions ) "Dynamically change dropdown column select in search modal" . https://stackoverflow.com/questions/48947183/