jqGrid显示用于行内编辑的“编辑"图标 [英] jqGrid show an 'edit' icon for in line editing

查看:86
本文介绍了jqGrid显示用于行内编辑的“编辑"图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the jqGrid with inline editing option. I want to show an edit icon if the cell does not have any values.

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

So I write a formatter:

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

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

The you can edit this text is displayed, when I click on it an input box is displayed correctly, however the input box as the initial value you can edit this ?

我该如何解决?

我正在通过struts 2 jquery tags plugin使用jqGrid,它基于jqGrid版本

I am using the jqGrid through struts 2 jquery tags plugin, which is build on jqGrid version

推荐答案

我认为您应该定义unformatter(

I think that you should define unformatter (unformat) together with the formatter. For example,

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.

I'm not sure how you can specify unformat in the struts2 grid plugin.

另一种方式是通过以下方式定义格式化程序

One more way would be defining formatter in the following way

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

它将允许您以与可以使用"date"等.

It will allows you to use formatter: "yourFormatterName" (or probably formatter = "yourFormatterName" in struts2) in the same way like you can use standard formatters "integer", "date" and other.

这篇关于jqGrid显示用于行内编辑的“编辑"图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆