【问题标题】:jqGrid: format cell value without changing actual (underlying) value?jqGrid:格式化单元格值而不更改实际(基础)值?
【发布时间】:2011-12-20 11:52:35
【问题描述】:

是否可以显示其他内容,同时保留原始单元格值以进行编辑?

我的 jqGrid 中的一列是“枚举”数据。对于编辑,我提供了 edittype: select + editoptions: enum-key:label set,这会导致正确显示 select 编辑器。但是,我想显示 label 而不是 enum-key 用于常规视图,而不仅仅是编辑。我知道我可以使用自定义单元格格式化程序,但这会导致 实际值 更改,然后我必须在编辑行之前再次查找键标签对...

【问题讨论】:

    标签: javascript jquery jqgrid jqgrid-formatter


    【解决方案1】:

    没有看到一些代码很难说,但是您不需要使用自定义格式化程序,只需使用formatter: 'select',如documentation所示。它特别指出“数据应包含键(“1”或“2”),但值(“一”或“二”)将显示在网格中”。

    如果您需要对输出进行更多控制,另一个选项是使用 editoptions 的 buildSelect 选项。例如,这是我在代码中的一个选择,还有其他示例。这个想法当然是您可以返回任何数据,然后根据需要对其进行操作以构建选择。然后数据事件更改函数确保为输入字段设置正确的值。

    { name: 'Id', index: 'Id', editable: true, hidden: true,  
         editoptions: { defaultValue: row_id,
                        dataUrl: "DataService.asmx/GetList",
                        buildSelect: function (data) {
                                     var s = '<select>';
                                     if (data && data.d) {
                                        //data is nested, so we need a few steps to get to the actual data
                                        var list = data.d;
                                        var opts = JSON.parse(list);
                                        var subList = opts.List;
                                        //loop through the data to build the options list
                                        for (var i = 0, l = subList.length; i < l; i++) 
                                            {   var ri = subList[i]; 
                                                s += '<option value=' + ri.Id + '>' + ri.Name + '</option>';
                                            }
                                      }
                                      else {
                                         s+= "<option value=0>No data to display</option>";
                                      }
                                      return s + "</select>"; 
                                } ,
                          dataEvents: [
                                  { type: 'change',
                                    fn: function (e) {
                                            $('input#Id').val(this.value);
                                    }
                                  }
                                  ]
    
                         },
           editrules:  {edithidden: true},
           edittype: 'select' 
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      • 1970-01-01
      • 2011-07-11
      相关资源
      最近更新 更多