CsvDownloadController

CsvDownloadController

CsvDownload Stimulus Controller

Handles CSV file downloads with AJAX requests and automatic file saving. Provides seamless CSV export functionality with error handling and proper resource cleanup.

Features:

  • AJAX-based file download
  • Automatic file saving via browser download
  • Configurable filename and URL
  • Error handling with user feedback
  • Automatic resource cleanup

Values:

  • url: String - URL to download CSV from
  • filename: String - Name for downloaded file

Targets:

  • button: Optional button element for click handling

Usage:

Constructor

new CsvDownloadController()

Source:

Methods

connect()

Description:
  • Connect controller to DOM Sets up event listeners for download triggering

Source:

disconnect()

Description:
  • Disconnect controller from DOM Cleans up event listeners

Source:

(async) download(event)

Description:
  • Download CSV file via AJAX and trigger browser download Handles the complete download workflow with error handling

Source:
Parameters:
Name Type Description
event Event

Click event from download trigger