Packagecom.iwobanas.controls
Classpublic class DataGrid2CSV

The DataGrid2CSV defines utility class to export data displayed in DataGrid to CSV format.

Note that DataGrid2CSV does not handle saving CSV file to filesystem or transmitting it over network, all what DataGrid2CSV does is returning String containing data in SCV format which then may be saved or transmitted by application code.



Public Properties
 PropertyDefined by
  columnSeparator : String = ","
String used to separate columns in exported data.
DataGrid2CSV
  includeHeader : Boolean = true
Flag indicating if header row should be added at the top of CSV document.
DataGrid2CSV
  rowSeparator : String = " "
String used to separate rows in exported data.
DataGrid2CSV
  target : DataGrid
Target DataGrid from which data should be exported.
DataGrid2CSV
  useRawData : Boolean = false
Flag indicating if raw data should be used when possible.
DataGrid2CSV
Public Methods
 MethodDefined by
  
getCSV():String
Get the data from DataGrid formatted as CSV.
DataGrid2CSV
Protected Methods
 MethodDefined by
  
escapeValue(value:String):String
Escape passed value so that it can be used as CSV field.
DataGrid2CSV
  
getDataRow(item:Object):String
Get data row in CSV format for a given DataGrid item.
DataGrid2CSV
  
getDataRows():String
Get all data rows in CSV format.
DataGrid2CSV
  
getFieldValue(item:Object, column:DataGridColumn):String
Get the String value for a given DataGrid item and column.
DataGrid2CSV
  
getHeadrRow():String
Get header row in CSV format.
DataGrid2CSV
Property detail
columnSeparatorproperty
public var columnSeparator:String = ","

String used to separate columns in exported data. According to RFC 4180 this should be comma. Column separator is not added after last column in row.

This property can be used as the source for data binding.

includeHeaderproperty 
public var includeHeader:Boolean = true

Flag indicating if header row should be added at the top of CSV document.

This property can be used as the source for data binding.

rowSeparatorproperty 
public var rowSeparator:String = " "

String used to separate rows in exported data. According to RFC 4180 this should be CRLF.

This property can be used as the source for data binding.

targetproperty 
public var target:DataGrid

Target DataGrid from which data should be exported. This may also be subclass of DataGrid for example MDataGrid.

This property can be used as the source for data binding.

useRawDataproperty 
public var useRawData:Boolean = false

Flag indicating if raw data should be used when possible. If true label functions will not be used for columns with dataField defined i.e. standard toString() function will be used. If false label functions will be used for all columns with label function defined.

This property can be used as the source for data binding.

Method detail
escapeValue()method
protected function escapeValue(value:String):String

Escape passed value so that it can be used as CSV field. By default all fields are surrounded with double quotes and double quotes inside field are escaped by adding double quotes (see RFC 4180).

Parameters
value:String — value which should be escaped

Returns
String — escaped value
getCSV()method 
public function getCSV():String

Get the data from DataGrid formatted as CSV. All parameters including target have to be set before call to this function.

Returns
String — DataGrid formatted as CSV or empty String if target is not set.
getDataRow()method 
protected function getDataRow(item:Object):String

Get data row in CSV format for a given DataGrid item.

Parameters
item:Object

Returns
String — data row in CSV format
getDataRows()method 
protected function getDataRows():String

Get all data rows in CSV format. This function iterates over DataGrid data provider and calls getDataRow().

Returns
String — all data rows in CSV format
getFieldValue()method 
protected function getFieldValue(item:Object, column:DataGridColumn):String

Get the String value for a given DataGrid item and column. Depending on useRawData flag this may be label created using label function or raw data converted to String.

Parameters
item:Object — DataGrid item for which value should be returned
 
column:DataGridColumn — DataGrid column for which value should be returned

Returns
String — value for a given DataGrid item and column
getHeadrRow()method 
protected function getHeadrRow():String

Get header row in CSV format.

Returns
String — header row in CSV format