tags:

views:

5512

answers:

5

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

+1  A: 

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:

    colModel :
    [
      {
       name:'seqnum',index:'seqnum', width:100,resizable:true,   
       align:"left",sorttype:"text",editable:true,edittype:"select",editoptions:
       { value:getSequenceNumbers()},editrules:{required:true}
      }
    ]

    function getSequenceNumbers(){
        $.getJSON("yourUrl", null, function(data) {
            if (data != null) {
                 //construct string.  
                 //(or the server could return a string directly)
            }
        });
    }

I suppose you could put the function inline as well, but I think it would be harder to read.

sanbornc
A: 

I have the same problem, Please if somebody know how to do that I´ll appreciate that...

Probably should have been a comment on the original question.
Chris Kimpton
A: 

What if I needed to get the current rowID and columnName in the getSequenceNumbers function? I'm trying to achieve a similar thing except my values are always changing hence I thought of populating the editoptions on the beforeCellEdit event to get the most current values(have posted a question in regards to it here: http://stackoverflow.com/questions/1291290/jqgrid-dynamic-select-option) however it's not quite working.

Jhanks,

Jo

Probably should have been a comment on the original question.
Chris Kimpton
+2  A: 

Use dataUrl... (see the wiki here).

Currently dataUrl generates a GET but if one pulls the code from Github the GET can be changes to a POST with no apparent side effects.

Martin
+2  A: 

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.

$(document).ready(function() {
 $.getJSON("GetURL", function(data) {
  setupGrid(data);
 });
});

function setupGrid(data) {
...
    colModel :
    [
      {
       name:'seqnum',index:'seqnum', width:100,resizable:true,   
       align:"left",sorttype:"text",editable:true,edittype:"select",editoptions:
       { value:data},editrules:{required:true}
      }
    ]

...
}
JT
i confirm, this method works.just tried it.Thanks JT
black sensei