Anatoliy
Anatoliy

Reputation: 321

jqgrid dynamic load of select list

I am struggling on dynamic load of select list options. I googled few hours with hope to find something helpfull. Found on this portal few things but they did not help so much... The logic of application is following: -we have an overview of archive boxes; -on edit of them I should get the multiple select list with options depending on archive box id - the list with already selected goods

I think I can load the select list options (in my case goods which are archived in this given box) via dataInit-function

editoptions: { dataInit: function( elem )

How can I solve this problem?

Any help is appreciated! Thanks in advance!

UPDATE 1

For me it is a pure mysticism:

'dataInit'=> "function (elem) { 
  var url = '/selectlist/?value='+elem.value;
  console.log(url);
  grid.setColProp('box_no', { editoptions: { dataUrl: url}});
}",

In the console I am getting on every click the correct url, but the selected list is populated only once with values of first row, which I selected. The option recreateForm is set true, but it doesn't help.

Upvotes: 0

Views: 1640

Answers (2)

Dariush Jafari
Dariush Jafari

Reputation: 5443

you can use jquery and ajax technology.
Dynamic Dependent Select Box using Jquery and Ajax
if you want to populate your select boxes use jquery chosen

Upvotes: 0

keithxm23
keithxm23

Reputation: 1280

You need the following attribute set in your colModel first..

search: true,
stype: 'select',
searchoptions: {dataUrl: "/api/select_options/3/"}

at the /api/select_options/3/ url, I simply return a string which is html code for select options like so:

<select role="select" class="input-elm" id="jqg5">
<option role="option">Select one</option>
<option value="in progress" role="option">In progress</option>
<option value="disbursed" role="option">Disbursed</option>
<option value="declined" role="option">Declined</option>
<option value="approved" role="option">Approved</option>
</select>

A couple of gotchas to be wary of there is escaping the double quotes. And also I had to set a blank option as the first option. Else, if the first option was selected, 'null' was sent as the value for that field.

I hope I made myself clear enough. Let me know if you have any further queries.

Upvotes: 1

Related Questions