Author Topic: Using editor.Init and initializing a "select" editor  (Read 2546 times)

ralph1996

  • Pro Ultimate
  • Jr. Member
  • *
  • Posts: 80
    • View Profile
Using editor.Init and initializing a "select" editor
« on: August 07, 2018, 05:14:50 am »
I am using the Init event of the column editor to initialize a custom dropdown library (multiselect.js) on the select element.  I have passed the options as JSON in the column.editor.  What I need to be able to do is to attach an attribute to each of the options in the HTML Select element that is passed to the init function.

I can always pass a separate array of data in the column that I can then map to an attribute in the Init handler if necessary.  But I would ideally like to be able to just add attributes to the option elements using the JSON data.  I don't want to use the dataMap property as the attributes are not intended to be mapped to a dataGrid column and they still won''t show up as attributes on the option elements.

I just wanted to know if I am missing something here.  We are currently using version 3.4 but will be upgrading to the latest version as soon as we do some internal code reorganization for other things.

Thank you

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Using editor.Init and initializing a "select" editor
« Reply #1 on: August 07, 2018, 05:47:47 pm »
I'm not much familiar with API of multiselect.js and integration of pqgrid with 3rd party libraries may or may not fully work.

Could you please share a jsfiddle example so that I may help you in any possible way.

ralph1996

  • Pro Ultimate
  • Jr. Member
  • *
  • Posts: 80
    • View Profile
Re: Using editor.Init and initializing a "select" editor
« Reply #2 on: August 07, 2018, 11:47:29 pm »
Unfortunately I don't have an external link to the jquery.multiselect.js library. It is documented at https://github.com/ehynds/jquery-ui-multiselect-widget.

But it really does not matter what library it is.  What I am asking for (and this is probably a feature request and not a bug etc.) is to be able to add attributes to the JSON for the options in a "select" editor.

So currently you might have:

colModel.editor.options = [{id:1, text:"One"},{id:2, text:"Two}];

What I would like is the ability to do something like this:

colModel.editor.options = {id:1, text:"One", attributes:[{attribute: "data-image-src", value: "../images/joy.png"}]},
                                    {id:2, text:"Two", attributes:[{attribute: "data-image-src", value: "../images/sad.png"}]}];

This would then create the HTML "select" element with the options and the options would have the "data-image-src" attribute applied to them.  Currently the only thing you can add is the pq_disabled and pq_selected properties.  Maybe this could simply be a pq_attributes property.

What I have done as a workaround  is to add the data-image-src property to the colModel JSON during the init function for the dropdown. I pull the data-image-src property from the colModel and attach them to the options in the HTML select before calling the mulltiselect library to initialize its version of the dropdown.

Hope this helps. And as I said this probably is more of a feature request.  It is not urgent to us since we have a work around.