Manuel Valle
Manuel Valle

Reputation: 297

jqGrid editotype: 'select, formatter: 'select' not working

I am using JSON to retrieve the values for the select element.
my colModel is :

{ name: 'position', editable: true, edittype: "select", formatter:'select',
    editoptions: {
        value: function() {
            var positions;
            $.ajax({
                url: "orthofixServices.asmx/GetPositionsList",
                data: "{}",
                async: false,
                success: function(data) {
                    positions = data.d;
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus);
                }
             });
            return positions;
        }

this is the response:

{
    "d": {
        "21": "CAP Pos 1",
        "41": "CAP Pos 2",
        "42": "CAP Pos 3"
    }
}

And the row sent back from the server to bind the grid is

{
    "d": {
        "page": 1,
        "total": 1,
        "records": 1,
        "rows": [
            {
                "id": 9,
                "name": "Julio",
                "nameid": 0,
                "title": "Doctor",
                "npi": "123-123",
                "license": "licabc",
                "licstate": "NV",
                "position": "41",
                "us": false,
                "hrate": 0,
                "rrate": 0
            }
        ]
    }
}

"position" is the field from the row that feeds the select element. After saving the row nothing shows on the grid. why? Should I save the key from the select as an Int or as a String. Does it matter? I tried both ways i never get to display anything on the grid for the select element. It should show: "CAP Pos 42"

Upvotes: 4

Views: 8589

Answers (2)

user2782196
user2782196

Reputation: 6625

The simple sad fact is that

formatter:'select',  editoptions: { value: function() { ...

is not implemented by jqGrid. The source code for $.unformat.select simply doesn't handle this case. Just convert the data to an array and pass it in to the function through value to get the same effect.

Upvotes: 1

Oleg
Oleg

Reputation: 221997

I would recommend you to use dataUrl and buildSelect properties of the editoptions. Additionally you will have to set some properties of the ajaxSelectOptions option of the jqGrid.

See here, here and here for examples of the usage.

Upvotes: 1

Related Questions