mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

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

Open lorenzos opened 8 years ago

lorenzos commented 8 years ago

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?!?

6pac commented 8 years ago

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.