javascript - jqGrid 显示 'edit' 图标用于行内编辑

标签 javascript jquery struts2 jqgrid struts2-jquery-grid

我正在使用带有内联编辑选项的 jqGrid。如果单元格没有任何值,我想显示一个编辑图标。

所以我写了一个格式化程序:

 function aFormatter(cellvalue, options, row) {
        if(cellvalue == null){          
              return 'you can edit this';
        }else{
            return cellvalue;
        }
 }

显示you can edit this文本,当我点击它时,输入框正确显示,但是输入框作为初始值you can edit this

如何修复它?

<小时/>

我通过 struts 2 jquery 标签插件 使用 jqGrid,该插件基于 jqGrid 版本构建

最佳答案

我认为您应该将取消格式化程序( unformat )与格式化程序一起定义。例如,

formatter: function (cellvalue) {
   if (cellvalue == null) {          
      return "<span class='ui-icon ui-icon-pencil'></span>";
   } else {
      return cellvalue;
   };
},
unformat: function (cellValue, options, elem) {
    return $(elem).text();
}

我不确定如何在 struts2 网格插件中指定 unformat

另一种方法是按以下方式定义格式化程序

(function ($) {
    "use strict";
    /*jslint unparam: true */
    $.extend($.fn.fmatter, {
        yourFormatterName: function (cellValue, options) {
            if (cellvalue == null) {          
                return "<span class='ui-icon ui-icon-pencil'></span>";
            } else {
                return cellvalue;
            };
        }
    });

    $.extend($.fn.fmatter.yourFormatterName, {
        unformat: function (cellValue, options, elem) {
            return $(elem).text();
        }
    });
}(jQuery));

它将允许您使用 formatter: "yourFormatterName" (或者在 struts2 中可能是 formatter = "yourFormatterName"),就像使用 standard formatters 一样。 “整数”“日期” 等。

关于javascript - jqGrid 显示 'edit' 图标用于行内编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38875186/

相关文章:

jquery - 将页面附加或加载到正文中,而不删除内部内容

c# - 稳步减慢从 javascript 到 WCF 服务的 ajax 调用

forms - 将属性标签中的值提交到操作表单

java - request.getParameter() 在 java servlet 中不能正确显示字符编码

java - 使用 "allowedTypes"参数限制struts2中的文件类型

javascript - 在 AngularJS 中评估指令属性中的表达式

javascript - 用于抓取的服务器端脚本语言的替代方案

javascript - iOS 5 在选项卡未激活时暂停 JavaScript

javascript - AngularJS单元测试: Initialize scope of a directive's controller

jquery - 使用 ASP.NET MVC 在客户端获取用户名