0

Is it currently possible access the clipboard conents from the onpaste event for the lightning datatable? If so how? If not then is there a work around?

I want to copy an paste from Excel and populate the lightning datatable from the contents.

    <lightning:datatable aura:id="definitions"
                         data="{! v.scenario_definition }"
                         columns="{! v.scenario_definition_columns}"
                         keyField="id"
                         onpaste="{!c.paste}" 
                         >

 paste: function(component, event, helper) {                       
        let paste_ok = document.queryCommandSupported("paste");
        console.log('Is paste ok: ' + paste_ok);
    }

I want the controller to parse the data on the clipboard then fill the data table. Should be simple.

  • 1
    Can you please edit your question to include the code you've tried so far? What exactly are you trying to do? – sfdcfox Mar 29 at 15:33
  • There is no such onpaste event on lightning:datatable. – Jayant Das Mar 29 at 16:39
1

According to this document, the onpaste event is not supported for the datatable.

Besides, the datatable object is designed more like a read/edit of existing rows than an actual spreadsheet.

You may want to try capturing the paste at the component level and then adding those rows yourself to the array (v.scenario_definition) that powers the datatable.

  • It isn't documented. onpaste="{!c.paste}" does work with lightning:datatable. An event does fire when you do Ctrl+v and you can handle it. However you don't have access to the clipboard. – ploc Mar 29 at 17:20
  • @ploc Anything undocumented thing could still work, BUT you should avoid using such things as it could stop working at a point and that you will not get any support around such thing from Salesforce – Jayant Das Mar 29 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.