The code I will display is not the complete code but I will try to guide you through the example.
This is how I have solved it:
In the .js file I have the following function and this is being called everytime a user right-click on a container with the class "right-click-toolbar". Right-clicking on this container brings up a modal with some options. One of the option is the export data link: