如何子类化Slickgrid的TextCellEditor? [英] How do I subclass the TextCellEditor of Slickgrid?

查看:90
本文介绍了如何子类化Slickgrid的TextCellEditor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为 Slickgrid 的TextCellEditor子类化?

How do I subclass the TextCellEditor of Slickgrid?

我想使用统一库为slickgrid中使用的编辑器设置样式.为此,我需要致电

I want to style the editors used in slickgrid using the uniform library; to do so I need to call

$("input, textarea, select, button").uniform();

生成html后的

;换句话说,在调用编辑器对象的init函数之后;目前,我只是复制整个编辑器源代码,并在init函数结束之前添加该行.我似乎不太优雅.

after the html is generated; in other words after the editor object's init function is called; Currently I just copy the entire editor source code and add that line just before the end of the init function. I just seems non elegant.

对于不熟悉slickgrid的人来说很清楚,这是代码:

to be clear to people unfamiliar with slickgrid, here is the code:

var myTextCellEditor = function(args) {
        var $input;
        var defaultValue;
        var scope = this;

        this.init = function() {
            $input = $("<INPUT type=text class='editor-text' />")
                .appendTo(args.container)
                .bind("keydown.nav", function(e) {
                    if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT) {
                        e.stopImmediatePropagation();
                    }
                })
                .focus()
                .select();

                $input.uniform();
        };

        this.destroy = function() {
            $input.remove();
        };

        this.focus = function() {
            $input.focus();
        };

        this.loadValue = function(item) {
            defaultValue = item[args.column.field] || "";
            $input.val(defaultValue);
            $input[0].defaultValue = defaultValue;
            $input.select();
        };

        this.serializeValue = function() {
            return $input.val();
        };

        this.applyValue = function(item,state) {
            item[args.column.field] = state;
        };

        this.isValueChanged = function() {
            return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
        };

        this.validate = function() {
            if (args.column.validator) {
                var validationResults = args.column.validator($input.val());
                if (!validationResults.valid)
                    return validationResults;
            }

            return {
                valid: true,
                msg: null
            };
        };

        this.init();
    }

其中 $ input.uniform(); 是唯一与默认TextCellEditor不同的行.

Where $input.uniform(); is the only line that is different from the default TextCellEditor.

推荐答案

您可以使用.live()按类将.ready()事件绑定到生成的html内容,因此它适用于所有将来的内容,而不仅限于存在的内容在最初的DOM中.

You could bind a .ready() event to the generated html content by class using .live() so it applies to all future content, not just content present in the initial DOM.

所以...

$('.classOfSlickGrid').live('ready', function() {
    $("input, textarea, select, button").uniform();
}

这篇关于如何子类化Slickgrid的TextCellEditor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆