easyui datagrid 自定义editor并根据实际情况(自定义options)判断返回多样的html控件

在添加的时候全部列都变成编辑状态,编辑的时候某些列不变成编辑状态,解决方法

1 自定义editor


$.extend($.fn.datagrid.defaults.editors, {
    Uploadfile: {//Uploadfile就是你要自定义editor的名称   
        init: function (container, options) {
             /////通过options传参数
            var status = $("#hidMode").val();
            if (status == 'edit') {
                var input = $("<a href='#' style='cursor:pointer;' value='" + options.url + "'  onclick='ShowFile(this.value)'  ></a>")
                           .appendTo(container);
            }
            else {
                var input = $("<input type='file'  id='Uploadfile'  name='Uploadfile'/>")
                          .appendTo(container);
            }
            return input;
        },
        getValue: function (target) {

            return $(target).val();
        },
        setValue: function (target, value) {
            var status = $("#hidMode").val();
            if (status == 'edit') {
                $(target).val($(target).val() + value);
                $(target).text(value);
            }
            else {
                $(target).val(value);
            }
        },
        resize: function (target, width) {
            var input = $(target);
            if ($.boxModel == true) {
                input.width(80);
            } else {
                input.width(width);
            }
        }
    }
});


dataGrid 使用 自定义editors

{
field: '文件名称', title: '文件名称',  getWidth(0.1), align: 'left', sortable: true,
 editor: {
 type: 'Uploadfile', 
options: { status: '', url: '/UploadFiles/MaterialFile/'}
         }
}
///options里面不可以使用 value,传输的参数是文本
原文地址:https://www.cnblogs.com/hbhzz/p/4075666.html