简体   繁体   English

如何设置从服务器到jqgrid中组合框的数据的选定索引

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

I have a jqgrid with a column with a combobox (select), and i set the values in editoptions through a function that returns the required options. 我有一个带有带组合框(选择)的列的jqgrid,并且我通过返回所需选项的函数在editoptions中设置了值。

My problems is how can i bring there the values saved: 我的问题是如何将保存的值带到那里:

eg: my options are : 1:yes,2:no,3:maybe 例如:我的选项是:1:是,2:否,3:也许

From the server a client have the option 2 saved and i want to show NO in the jqgrid. 从服务器上,客户端保存了选项2,我想在jqgrid中显示NO。

heres a bit of my code: 这是我的一些代码:

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()}

           }

You don't posted enough details about what you do, but I guess that adding formatter: "select" to the column should solve the problem. 您没有发布有关操作的足够详细信息,但是我想在该列中添加formatter: "select"应该可以解决问题。 The usage of async call in the formatter is absolutely wrong way. 在格式化程序中使用异步调用是绝对错误的方式。 If you set already editoptions.value then formatter: "select" will uses the information and will decode the input data 1, 2 and 3 to the texts 'yes' , 'no' or 'maybe' which will be displayed in the corresponding column of the grid. 如果您已经设置了editoptions.value那么formatter: "select"将使用该信息并将输入数据1、2和3解码为文本'yes''no''maybe' ,这些文本将显示在相应的列的网格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM