我如何使用服务器中的数据将所选索引设置为 jqgrid 中的组合框

How can i set the selected index with data from server to a combobox in a jqgrid

我有一个 jqgrid,其中有一列带有组合框 (select),我通过 returns 所需选项的函数在 editoptions 中设置值。

我的问题是如何将保存的值带到那里:

例如:我的选择是:1:yes,2:no,3:maybe

客户端从服务器保存了选项 2,我想在 jqgrid 中显示 NO。

这是我的一些代码:

function getAllSelectOptions() {
    var state= {
        '1': 'yes', '2': 'no',
        '3': 'maybe' };
    return state;
}



  function formatTest(cellvalue, options, rowObject) {        

        $.ajax({
            type: "POST",
            url: "Customers.aspx/getOptions",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            success: function(result) {
             //return options.colModel.editoptions.value[result.d]; shows me the value from server, but i cant return it.
            },

            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus + ": " + XMLHttpRequest.responseText);
            }
        });

    }


//combo
    {
       name: 'column1', index: 'column1', width: 23,

       align: 'center',

       editable: true,

       edittype: 'select',

       formatter: formatTest,

       editoptions: {value: getAllSelectOptions()}

           }

您没有发布足够的详细信息来说明您的工作,但我想在专栏中添加 formatter: "select" 应该可以解决问题。在格式化程序中使用异步调用是绝对错误的方式。如果您已设置 editoptions.value,则 formatter: "select" 将使用该信息并将输入数据 1、2 和 3 解码为文本 'yes''no''maybe'将显示在网格的相应列中。