GasKa
GasKa

Reputation: 663

Custom columns name when exporting Sonata Admin

I'm trying to export some columns and few of them have custom values like (0=closed, 1=pending, 2=under revision, 3=approved). It is possible to export their names: Closed / Pending etc instead of 0,1,2,3... ? How ?

I tried using getExportFields() from Sonata, but all I did was to change the label.

Id     Name      Status                
 1     Item1       0
 2     Item2       3

to

Id     Name      Status                
1      Item1     Closed
2      Item2    Approved

Upvotes: 4

Views: 1078

Answers (1)

M Khalid Junaid
M Khalid Junaid

Reputation: 64466

Yes for each column define a new property and a method in your entity which will return you the text for each value like

protected $someColumnValueAsText;
public function getSomeColumnValueAsText(){

    if($this->status == 0){
    return 'Closed';
    }
    if($this->status == 1){
    return 'Pending';
    }
    //... and so on
}

And in getExportFields define your new property as

public  function getExportFields(){
    return array(
        'Status'=>'someColumnValueAsText',
         ....// Other properties
        );
}

Upvotes: 3

Related Questions