Copy and Paste with complex objects

Tags: #<Tag:0x00007efc65702958>

Hey,

I have complex objects lying behind each cell of my table. In order to display the values correctly I had to write a custom cell-renderer and a custom-editor. That works fine so far but I ran into problems when trying to copy and paste from/to handsontable.

To solve the copy-issue ([Object object]) I had to overwrite the toString() method of my objects. Paste was a little more complex, since plain values have to be converted into objects again. I did not find a solution to this without modifying handsontable-code, which i’d rather not touch.

My object looks like this:

{
  value: xxx,
  comment: yyy
}

I changed the following lines (starting at line 4801, Version: 1.4.0, baseVersion: 0.25.0) in handsontable.full.js

} else if (orgValue !== null && typeof orgValue === 'object') {
    value = {
        value: value,
        toString: function () { return this.value }
    };
    //pushData = false;
}

My question is:

  • Is there another solution to this issue
  • If not, would it be possible to provide a hook (so that I don’t need to modify handsontable-code)

Best regards
Tom

Hi Tom,

That’s right - it’s not a good idea to change the source code as your solution may interfere with future releases.

Please share more information about which hook you would like to have?

Hi Aleksandra,

I’d like to have a hook to be able to modify pasted-values before applying them to the grid. Personally I’d name it beforeSetObjectValueAtCell(val), but feel free to take another name :slight_smile:
Calling the hook would then look (in pseudo-code) something like this (again at line 4801):

} else if (orgValue !== null && typeof orgValue === 'object') {
    if (typeof(beforeSetObjectValueAtCell) !== 'undefined') {
        value = beforeSetObjectValueAtCell(value);
    } else {
        pushResult = false;
    }
}

It would be even better if i could set pushResult within the hook.

It sounds like a good idea. I’ll mark this issue as a feature request.

Thank you :wink: