I got a basic jqGrid working in my coldfusion project. One of my fields in jqGrid is a combo box. Currently the editoption values are hard coded just like below.
colModel :
[
{
name:'seqnum',index:'seqnum', width:100,resizable:true,
align:"left",sorttype:"text",editable:true,edittype:"select",editoptions:
{ value:"1:one;2:two"},editrules:{required:true}
}
]
I am trying to figure out a way to populate the drop-down from a query/url.
Any help would be greatly appreciated.
Thanks in advance
The $.getJSON / getSequenceNumbers() answer does not work as presented. There is no way to return data from a callback as the return value for getSequenceNumbers() because the callback is asynchronous. You either need to use the dataURL method suggested by Martin or setup the jqGrid inside of the $.getJSON callback.
Create a function that uses json to query the url. This function should return a string in the format "1:one;2:two".
For example:
I suppose you could put the function inline as well, but I think it would be harder to read.
I know this is an old question, but it I've find the same problem.
I solve this by combination of dataUrl and ajaxSelectOptions.
Note that dataUrl string ARE static, means you cannot send different parameters each time add/edit occurs. Below code WILL NOT WORK !
To send parameters such id, you can use ajaxSelectOptions .
The function which return selected_id will be executed each time the add/edit occurs. Hope this helps !
Lets say that in your ColModel you have a column like this:
You must first declare that its a select element with this:
Then, in the editoptions parameter add a dataUrl like this:
The filename.php must return a "select" element with it's options, here's an example:
Hope this helps.
It's worth noting that you can sidestep the issue completely if you're using a server-side scripting language. For example with PHP you might use
Then just setup the PHP function getData() further up the page to return a suitable string, for example
Maybe not as elegant or as portable as handling everything in jQuery, but conceptually easier I think.
I adapted the code for searchoptions instead of editoptions. However it was automatically selecting the first option and filtering the list so I added the following to alleviate that.