FilamentF
Filament9mo ago
Arjen

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:
[
  {
    "data": {"id": "dN268g", "label": "Question", "data_type": "string", "is_required": true},
    "type": "text_input"
  },
  //...
]

When a person fills in the sign up form, the extra fields get saved in CourseRegistration in a DB column like so:
{"Question": "Answer", //...}

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.
Was this page helpful?