SlickGrid icon indicating copy to clipboard operation
SlickGrid copied to clipboard

Custom editor's applyValue() should be treated as static, but I need args.column definition

Open lorenzos opened this issue 9 years ago • 1 comments

The guide to implement a custom editor says:

Deserialize the value(s) saved to "state" and apply them to the data item. This method may get called after the editor itself has been destroyed; treat it as an equivalent of a Java/C# "static" method - no instance variables should be accessed.

But suppose I have my custom editor for a many column in my row, how can I update the item field if I can't access editor instance's args.column to get the field name?

this.applyValue = function(item, state) {
    item[args.column.field] = state; // I should't use instance variables, i.e. args
};

The code above works, however, but I'm unsure about edge cases in which it does not... Because if not, why that warning in the docs?!?

lorenzos avatar Jan 08 '16 14:01 lorenzos

Hi lorenzos, I wouldn't worry about it. All the other editors use args.

I suspect that in any case if the editor had been destroyed, and the function was called, the value of args and any local variables would be preserved in a closure. So reading is probably OK. However, trying to set their value would probably not be a good idea.

6pac avatar Feb 03 '16 06:02 6pac