When editing column with edittype: select and multiple: true, jqGrid sends the data to the server as comma-separated values. Is that possible to bind some event to this specific column, which will return an array instead of comma-separated values?
I’d like to avoid using serializeEditData event, since
- this one is grid-specific, not column-specific which would be a trouble for me – I’m trying to separate column logic from grid logic
- it does not sound like a good idea to convert array to string, and the string to the very same array again.
I think that you will have to use
edittype: 'custom'in the case and provide your custom implementations ofcustom_elementandcustom_valuemethods ofeditoptions. If the value from the custom input element will be need to read jqGrid will callcustom_valuemethod with the parameter'get'parameter. Your implementation ofcustom_valuemethod could return array of items in the case.It’s important to understand that in general you will need to implement custom formatter which allows to display array of data which are input for multiselect. Fortunately
formatter: "select"has the linewhich convert array to comma separated items. Because of the line the array will by converted to string by usage of
.join(",")andformatter: "select"successfully accepts arrays as input.The demo
demonstrates the described above approach. It uses the following code:
In the above code I use
$.jgrid.createElto create multivalue select by existing code of jqGrid. The only thing which one need to do is removing ofcustom_elementandcustom_valuefrom the options to prevent unneeded call of the methods from setAttributes. If one would modify the line ofsetAttributescode and include"custom_value"and"custom_element"in the list of excluded attributes the expression$.extend(true, {}, options, {custom_element: null, custom_value: null})could be reduced tooptions.In the way we get almost the same
<select>as usingedittype: "select". There are two differences only:<select>element created inside ofedittype: "custom"will have additional attributeclass="customelement"<select>element created inside ofedittype: "custom"will be wrapped (will be direct child) inside of<span class="editable">...</span>Such differences seems be not important in our case.
UPDATED: The code of
setAttributesmethod is now fixed in the main code of jqGrid on the gtihub (see the suggestion and the commit). So in the next version of jqGrid (higher as 4.4.1) one could reduce the code ofcustom_elementtoSee the corresponding demo.