Ive got a jqGrid where i have a some columns and 1 of the columns is a dropdownlist(select) populated from database.
What i want is : When im not in editmode column with
What you need to do is to use
editoptions: { dataUrl: '@Url.Action("ConstructSelect")' }
instead of
editoptions: { value: data }
Depend on the format of the output of the action ConstructSelect
you can need to use an additional property buildSelect
of the editoptions
. jqGrid expected that the server response on the HTTP 'GET' request of dataUrl
will be HTML fragment which represent <select>
. For example:
<select>
<option value="de">Germany</option>
<option value="us">USA</option>
</select>
If the server return other formatted data, like JSON data
["Germany","USA"]
or
[{"code":"de","display":"Germany"},{"code":"us","display":"USA"}]
you can write JavaScript function which convert the server response to the HTML fragment of the <select>
and set the value of the property buildSelect
to the function.
In the answer you will find an example of the function.
If your action support only HTTP POST and no GET you will have to use ajaxSelectOptions: { type: "POST" }
parameter additionally, to overwrite the type of the corresponding ajax
requests. In the same way you can overwrite other ajax
parameters. For example you can use
ajaxSelectOptions: { type: "POST", dataType: "json"}
(defaults are type : "GET"
and dataType: "html"
)
Some other small remarks to the code:
$(document).ready(function () {
inside of another $(document).ready(function () {
.'Id'
instead of 'id'
. So jqGrid will not find the id
property. You can a) rename
'Id'
to 'id'
b) include additional parameter jsonReader: {id: 'Id'}
c) include additional property key: true
in the definition of the column 'Id'
. Any from the ways will solve the described problem.edittype: 'text'
, sortable: true
or editable: false
. See jqGrid documentation which describes the default values of all colModel
properties.imgpath
parameter of jqGrid. The parameter is not exist since many many versions of jqGrid (see here).