Hi there,
I have quite some dozen DownloadButton in my app. For each button, actually I associate with a downloading function method in the Controller (e.g. DownloadButton(‘Download Excel file’, method=‘download_spreadsheet’) ). I do not want to create as many downloading function method as the number of DownloadButton, but only one function that accepts some arguments. But as the function name is put in string format, do you think there is a way to achieve that?
Thanks,
Huy
Welcome to the VIKTOR Community!
I think you could write a generic download method on your controller in combination with an optionfield that lists the different download options. In the method you would then write some logic to trigger the correct method based on the selected option.
Hope this helps,
Regards,
Raoul
Hi,
Thank for your suggestion. I imagine that with this solution, before clicking onto a given DownloadButton, the user needs to choose the right option in the optionfield. In this case, it’s not so user-friendly as the users expect to download the right file just by clicking onto the downloadbutton they want. Is there a way to know which button that has just been clicked?
Thanks
Well in that case you could have a single download button with the option field (depending on the number of options you could go for a radio variant), like so:
The solution of having only one downloadbutton is something we thought about. But it will be the last solution if we cannot deal with having all the downloadbutton as we have actually.
By the way, the problem we have came from another one. Indeed, we have one Entity with all the fields completed by the user. In there, the user could upload quite a lot of files by using FileField. Now we want to pass the Entity into another ChildEntityManager (distinguished by Entity Type name). As we could not find how to change the Type name of the Entity, we just create a new Entity with the expected Type name and all the parameters of the old Entity. However, in the new Entity, all the uploaded files are lost. It’s the reason why we had to add a DowloadButton just next to each FileField so that the user can download the corresponding file if needed. So if you can help us on how to change the Type name of an Entity, or how to keep the uploaded files when creating a new Entity from an existing one, it’s really appreciated.
Thanks