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()

Methods

connect()

Connect controller to DOM Sets up event listeners for download triggering

disconnect()

Disconnect controller from DOM Cleans up event listeners

(async) download(event)

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

Parameters:
NameTypeDescription
eventEvent

Click event from download trigger