Dynamic ExportColumns based on JSON field in Exporter, possible?
Hi, is it possible to define extra dynamic export columns based on a JSON array from a owner record in a relation manager? My use case: I've got a Course resource with a CourseRegistration (HasMany) relation manager. The Course resource contains a Builder field that is used to insert extra form fields for when people sign up for a course. For example:
When a person fills in the sign up form, the extra fields get saved in CourseRegistration in a DB column like so:
I've added an Exporter to the CourseRegistration relation manager, and I want to create extra columns for every extra form field, so that the csv/xlsx for all signups doesn't contain one column with above data. Is this possible? Is there a way to get a hold of the owner record inside the
public static function getColumns()
method inside an Exporter? Basically I need a way to pass the owner record to the exporter class.2 Replies
I've now tried using sessions, but that didn't work because the export job doesn't use the current session. It worked when mapping the columns.
I found a workaround that works for my use case. I added the ID to the
ExportAction->options([])
array and I've overridden the getCachedColumns
method to not get the columns from the static getColumns
method, but from a different method that can read the options. I've kept the session from before, because you can't read the non-static options in the static getColumns
method.
yes, it's entirely possible to efine extra dynamic export columns based on a json field, and you've alreay made a good attempt with your workaround