当前位置: 动力学知识库 > 问答 > 编程问答 >

servlets - jqGrid: dataurl not working

问题描述:

I'm new to both jQuery and jQGrid. I tried to populate a dropdown combobox in the grid with data coming from server, I'm in java servlet environment.

I used dataUrl method and many others but still no luck with populating combo.

my js looks like:

...

{name:'idTipologia',index:'idTipologia', width:80,editable: true,edittype:"select",editoptions:{dataUrl: "/sohara/comboTipologiaAction.do"}...

...

my server side code basically is:

take a list from server, format data (whether json or not), open a PrintWriter, write info in it.

I tried both JSON conversion and plain text from Firebug I can see the response correctly formatted ("1:VALUE1;2:VALUE2")but the dropdown remains empty.

My question is:

Is there a peculiar way to organize the data in order to make this combo population?

Any help appreciated.

网友答案:

According to the jqGrid documentation, your problem is that the dataUrl needs to return HTML containing the SELECT element, not JSON:

The editoptions dataUrl parameter is valid only for element of edittype:select. The dataUrl parameter represent the url from where the html select element should be get.

When this option is set, the element will be filled with values from the AJAX request. The data should be a valid HTML select element with the desired options - something like:

<select> 
<option value='1'>One</option> 
<option value='2'>Two</option> 
...
</select>

So the easiest solution is for you to just return HTML.


That said, I do not like the idea of returning UI elements directly. Another option is to use the buildSelect function to construct the SELECT element for you:

This option is relevant only if the dataUrl parameter is set. When the server response can not build the select element, you can use your own function to build the select. The function should return a string containing the select and options value(s) as described in dataUrl option. Parameter passed to this function is the server response

This answer provides an example of how to use buildSelect.

分享给朋友:
您可能感兴趣的文章:
随机阅读: