jqGrid show an 'edit' icon for in line editing

后端 未结 2 2000
醉酒成梦
醉酒成梦 2021-01-26 04:55

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 aFo         


        
相关标签:
2条回答
  • 2021-01-26 05:46

    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.

    0 讨论(0)
  • 2021-01-26 05:52

    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;
       }
    }
    
    0 讨论(0)
提交回复
热议问题