jqGrid show an 'edit' icon for in line editing

拥有回忆 提交于 2019-12-02 12:49:32

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

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

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.

This will show an "edit" icon instead of "you can edit this" in the grid

function aFormatter(cellvalue, options, row) {
   if(cellvalue == null) {          
      return '<span class="ui-icon ui-icon-pencil"></span>'
   } else {
      return cellvalue;
   }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!