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.

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.