easyui grid 里的可编辑text 加清空图标

    $.extend($.fn.datagrid.defaults.editors, {
        text: {
            init: function (container, options) {
                var _opt = $('<input type="text" class="datagrid-editable-input">');
                var curField = container.prevObject.prevObject.attr('field'); 
                if (curField == "我们需要加清空的字段" ) {   
                    var button = $('<input type="text" class="easyui-textbox"> ').appendTo(container);
                    button.textbox({ 
                        //添加清除图标
                        icons: [{
                            iconCls: 'icon-clear',
                            handler: function (e) {
                                button.textbox('clear');

                   //modelTextClear 是自定义清除 grid 里数据 的函数
                                modelTextClear(curField);
                            }
                        }]
                    });

                    if (typeof (options.onClick) == 'function') {
                        var el = button.next().children('.textbox-text');
                        el.click(function () {
                            options.onClick(el);
                        });
                    }
 
                    return button; 
                }
                if (typeof (options.onChange) == 'function') {
                    _opt.change(function () {
                        options.onChange(_opt);
                    });
                }
                if (typeof (options.onFocus) == 'function') {
                    _opt.focus(function () {
                        options.onFocus(_opt);
                    });
                }
                if (typeof (options.onKeyup) == 'function') {
                    _opt.keyup(function () {
                        options.onKeyup(_opt);
                    });
                }
                var input = _opt.appendTo(container);                
                if (container.closest('td[field]').attr('field') == 'ApplyDate') {
                    _opt.addClass('form-control');
                    return input.datetimepicker({
                        minView: "month", //选择日期后,不会再跳转去选择时分秒 
                        format: "yyyy-mm-dd", //选择日期后,文本框显示的日期格式 
                        language: 'zh-CN', //汉化 
                        autoclose: true
                    });
                }else {
                    return input;
                }
            },
            destroy: function (target) {
                $(target).remove();
            },
            getValue: function (target) {
                return $(target).val();
            },
            setValue: function (target, value) {
                $(target).val(value);
            },
            resize: function (target, width) {
                $(target)._outerWidth(width);

          //以下是处理图标不显示的问题   因为span 占满了单元格
                var curField = target.closest('[field]').attr('field');
                if (curField == "ReimbursementID" || curField == "CostCenterDisplayName" || curField == "ProductDisplayName") {
                    target.next('.textbox').css('width', width);
                    target.next().children('.textbox-text').css('width', width - 26);
                }
            }
        }
    });    

  

原文地址:https://www.cnblogs.com/yigexiaojiangshi/p/9600149.html