easyUI中datagrid 将 text 设为不可编辑,该怎么处理

2025-05-15 08:37:56
推荐回答(1个)
回答(1):


1、

var vareditor=$('#datagridId').datagrid('getEditor', { index:rowIndex, field:'fieldName' );


vareditor.target.prop('readonly', true);

2、扩展datagrid字段的editor

$.extend($.fn.datagrid.defaults.editors, {

    textReadonly: {

        init: function (container, options) {

            var input = $('').appendTo(container);

            return input;

        },

        getValue: function (target) {

            return $(target).val();

        },

        setValue: function (target, value) {

            $(target).val(value);

        },

        resize: function (target, width) {

            var input = $(target);

            if ($.boxModel == true) {

                input.width(width - (input.outerWidth() - input.width()));

            } else {

                input.width(width);

            }

        }

    }

});

然后字段的editor:'textReadonly'