简体   繁体   中英

How do I subclass the TextCellEditor of Slickgrid?

How do I subclass the TextCellEditor of 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();

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.

edit:

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();
    }

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

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.

So...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM