Search code examples
javascriptslickgrid

Slickgrid editor finish event


I have set Editors.Text or edit.

 {id: "label", name: "name", field: "label",editor: Editors.Text,width: 80},

This enables editing for field on browser.

But how can I catch when editing is finished??

I am checking the event list of slickgrid.

However can't find the appropriate event.

How can I catch the event after editing columns??


Solution

  • It appears that there is no generic event for this - probably not a bad idea to add one. I suspect it is expected that you would write a custom editor and add the event directly to that rather than adding it to the grid.

    I assume you want to update some related data or UI when the editing is complete?

    [Edit]

    The editor has events encapsulated in it for doing this - the grid uses a plugin model with loadValue and applyValue to read/write the data source. I'll post an example of my personal text editor here, as it may help. Note that I have written a data provider for my personal grid to allow it to interface to several custom data objects - this isn't in the standard one you should be using, which is here.

    function TextEditor(args) {
        var $input;
        var defaultValue;
        var scope = this;
    
        this.init = function () {
            $input = $("<INPUT type=text class='editor-text' />")
          .appendTo(args.container)
          .on("keydown.nav", function (e) {
              if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT) {
                  e.stopImmediatePropagation();
              }
          })
          .focus()
          .select();
            $input.width(args.container.clientWidth); /* mod */
        };
    
        this.destroy = function () {
            $input.remove();
        };
    
        this.focus = function () {
            $input.focus();
        };
    
        this.getValue = function () {
            return $input.val();
        };
    
        this.setValue = function (val) {
            $input.val(val);
        };
    
        this.loadValue = function () {
            defaultValue = args.grid.getDataProvider().getValueByColName(args.rowIndex, args.column.field);
            defaultValue = defaultValue || "";
            $input.val(defaultValue);
            $input[0].defaultValue = defaultValue;
            $input.select();
        };
    
        this.serializeValue = function () {
            return $input.val();
        };
    
        this.applyValue = function (state) {
            args.grid.getDataProvider().setValueByColName(args.rowIndex, 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();
    }