Exports - Jet\DataListing_Export

Each data export used in a data list must be represented by its own class, which must inherit from this abstract Jet\DataListing_Export.

For an example, see the sample application in the EventViewer.Admin, EventViewer.REST and EventViewer.Web modules.

Method Overview

Method Meaning of
public setListing(
DataListing $listing
) : void
The list automatically sets the export reference to itself when the export is passed. This method is used for this purpose.
public getListing(
) : DataListing
Returns the instance of the data list to which the export belongs.
public getKey(
) : string
Returns a unique key identifying the export. It is recommended to implement as follows: class Listing_Export_CSV extends DataListing_Export_CSV
{
    public const 
KEY 'CSV';
    
    public function 
getKey(): string
    
{
        return static::
KEY;
    }
}
And the export can then be handled as follows: $listing->exportListing_Export_CSV::KEY )->export();
public getTitle(
) : string
Returns the generated and possibly already translated export header.
public getIcon(
) : string
Can return the name of the export icon. Optional.
public export(
array $column_keys=[]
) : void
Executes itself from the columns specified by the $column_keys parameter, or from the currently displayed columns.

It works as follows:
  • Based on the filter and sort settings, it will load the relevant data items.
  • Asks column definitions to prepare the data for export. See column definitions, getExportHeader() and getExportData($item) methods.
  • Calls the formatData( array $export_header, array $data ) method, which takes care of transforming the data into the desired format and sends the data to the output.
abstract protected formatData(
array $export_header,
array $data
) : void
Transforms the data into the required format and sends the data to the output. Example of implementation - conversion to CSV: protected function formatData( array $export_header, array $data ): void
{
    
$file_name $this->generateFileName();
        
    
header'Content-Type: text/csv' );
    
header'Content-Disposition: attachment;filename="' $file_name '"' );
    
header'Cache-Control: max-age=0' );
        
    
$fp fopen('php://output''w');
        
    
fputcsv$fp$export_header );
        
    foreach( 
$data as $row ) {
        
fputcsv$fp$row );
    }
        
    
fclose$fp );
        
}
Previous chapter
Jet\DataListing_Filter_OptionSelect
Next chapter
Bulk operations - Jet\DataListing_Operation