3

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.

asked Jun 20, 2018 at 11:47

1 Answer 1

2

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;
}
Chirag Patel
6,1662 gold badges26 silver badges66 bronze badges
answered Jun 21, 2018 at 11:51
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.