In my custom module admin UI component data grid there is a one column is named "Status" all data display perfectly.
But my problem is when i export data then "Status" column value display 0 OR 1 because in DATABASE value is stored as 0 and 1
And what i want is When i export - then in csv file that status values should be 0 => Pending and for 1 => Active how can i achieve this.
Any help would be appreciated. Thanks.
1 Answer 1
You need to override getRowData() function of vendor/magento/module-ui/Model/Export/MetadataProvider.php
This function print row data to csv or xml file at the time of export
So you final code will look like:
public function getRowData(DocumentInterface $document, $fields, $options)
{
$row = [];
$key = array_search ('status', $fields);
foreach ($fields as $column) {
if (isset($options[$column])) {
$key = $document->getCustomAttribute($column)->getValue();
if (isset($options[$column][$key])) {
$row[] = $options[$column][$key];
} else {
$row[] = '';
}
} else {
$row[] = $document->getCustomAttribute($column)->getValue();
if($column == 'status'){
switch ($row[$key]){
case 0:
$row[$key] = self::STATUS_PENDING;
break;
case 1:
$row[$key] = self::STATUS_ACTIVE;
break;
case 2:
$row[$key] = self::STATUS_INACTIVE;
break;
case 3:
$row[$key] = self::STATUS_DISAPPROVED;
break;
case 4:
$row[$key] = self::STATUS_VACATION_MODE;
break;
case 5:
$row[$key] = self::STATUS_CLOSED;
break;
}
}
}
}
return $row;
}