tonytomov / jqGrid

jQuery grid plugin

Home Page:www.trirand.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal for improving feature - Dynamic values for "select" formatter

unle70 opened this issue · comments

Hi Tony,

When using the "select" formatter, the documentation is giving a quick hint that the editoptions.value (and formatoptions.value) can actually be a function.
I see that indeed you can define a function there, for dynamically setting the select options, but there's a problem. This function is getting NO input parameters and "this" is pointing to some internal jqGrid object (not a DOM element).

I think it would be very nice if this function could have some useful parameters, maybe the same as for the custom formatter, and "this" should point to the grid. It would make things easier when implementing dynamic values.

Hello Udi,

Thanks for the recommendation.

I think we can pass the grid element (this) and the options (which contain everything you need).

I will refer this issue when these are added.

Thank you
Tony

You can test the new addition as described into the commit.

Hi Tony,

Well, for having a "full solution", there are 3 places that need to be handled:

  1. Editing - editoptions.value - You have handled
  2. Formatting - When using type 'select', this formatter will try formatoptions.value and if not found, will use editoptions.value - This was not yet handled
  3. Filtering - searchoptions.value needs to be handled. I believe the same logic should apply as in formatting. If searchoptions.value is not found, need to default to formatoptions.value or editoptions.value. - This was not yet handled.

#1 looks OK at this time, but in my case I cannot use it without have #2 and #3 working as well.

The select as function can be used in editoptions and searchoptions.
This is true since the select as function is defined in createEl function which is called every time when input select element is created including in searching methods.

Not sure that the logic you describe should be applied, instead that historically in certain places it is available.
I think that every module (formatter, edit, search) should have his own options and not use the option from the other when it is not defined.

Hi Tony,

When I tried to use the "function" type "value" for the "select" type in formatting, it didn't call the function. I looked at the code and didn't see any checking for type "function" there (I think it's in "jquery.fmatter.js" line 234 and on). I only see checking whether it is a String or an Object. Am I wrong about this location?

As for the different options, I understand your point. It's just that I saw the code mentioned above, and saw that it DOES have this fallback from formatoptions to editoptions (line #242). So that is why I was proposing the same line of thinking for searchoptions. But it's OK if you keep them separate.