jqGrid Switch a field to dropdown from text

后端 未结 1 1172
走了就别回头了
走了就别回头了 2021-01-28 15:38

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

相关标签:
1条回答
  • 2021-01-28 15:53

    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:

    • you should not place $(document).ready(function () { inside of another $(document).ready(function () {.
    • You use '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.
    • You can remove default properties like edittype: 'text', sortable: true or editable: false. See jqGrid documentation which describes the default values of all colModel properties.
    • You should remove imgpath parameter of jqGrid. The parameter is not exist since many many versions of jqGrid (see here).
    0 讨论(0)
提交回复
热议问题