# Migx database CSV export edit titles and order \[solved\]

**URL:** <https://community.modx.com/t/migx-database-csv-export-edit-titles-and-order-solved/7672>\
**Category:** Random\
**Tags:** migxdb\
**Created:** [April 6, 2024, 9:10am UTC](https://community.modx.com/t/migx-database-csv-export-edit-titles-and-order-solved/7672 "2024-04-06T09:10:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ysanmiguel](https://community.modx.com/user_avatar/community.modx.com/ysanmiguel/32/285_2.png) [@ysanmiguel](https://community.modx.com/u/ysanmiguel)\
**Post date:** [April 6, 2024, 9:10am UTC](https://community.modx.com/t/migx-database-csv-export-edit-titles-and-order-solved/7672/1 "2024-04-06T09:10:40Z")

</div>

Good afternoon, I have a migxdb implementation running very well, it has an option in the manager area to “Export Current View” to an CSV file.  
It’s exporting the file but the columns titles at the top are the same names and order that the database, normally the names in the database had no spaces or are not complete, they are just references, the question is:

Is it possible to rename and change the order of the columns in the CSV file? (obviously not after it’s exported, just in case!).

Thanks for your help, cheers! 👍

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [April 6, 2024, 11:06am UTC](https://community.modx.com/t/migx-database-csv-export-edit-titles-and-order-solved/7672/2 "2024-04-06T11:06:37Z")

</div>

Usually with MIGX you can customize the behavior by creating a custom processor. (Copy the default processor to the folder of your custom package and change the code).

For this, it’s either the “export” or “exportcsv” processor.  
What Actionbutton are you using? “exportview” or “exportcsvmigxdb”?

---

<div class="post-metadata">

**Author:** ![bruno17](https://community.modx.com/user_avatar/community.modx.com/bruno17/32/71_2.png) [@bruno17](https://community.modx.com/u/bruno17)\
**Post date:** [April 6, 2024, 6:40pm UTC](https://community.modx.com/t/migx-database-csv-export-edit-titles-and-order-solved/7672/3 "2024-04-06T18:40:04Z")

</div>

I think, you can use a hooksnippet (getcustomconfigs)

> <https://github.com/Bruno17/MIGX/blob/352a909a3e06dcdb2dfe8696e52990b1a0f4df81/core/components/migx/processors/mgr/default/exportcsv.php#L65>

which sets a exportfields config

> <https://github.com/Bruno17/MIGX/blob/352a909a3e06dcdb2dfe8696e52990b1a0f4df81/core/components/migx/processors/mgr/default/exportcsv.php#L241>

---

<div class="post-metadata">

**Author:** ![ysanmiguel](https://community.modx.com/user_avatar/community.modx.com/ysanmiguel/32/285_2.png) [@ysanmiguel](https://community.modx.com/u/ysanmiguel)\
**Post date:** [April 8, 2024, 1:31pm UTC](https://community.modx.com/t/migx-database-csv-export-edit-titles-and-order-solved/7672/4 "2024-04-08T13:31:22Z")

</div>

> [@halftrainedharry](#):
>
> exportcsvmigxdb

I’m using: exportcsvmigxdb  
Thinking that, is the right one to export the entire DB and not just what is in the screen!

I’ll try @bruno17 approach and let you all know.

Thanks for your advice. AS ALWAYS! 👍

---

<div class="post-metadata">

**Author:** ![ysanmiguel](https://community.modx.com/user_avatar/community.modx.com/ysanmiguel/32/285_2.png) [@ysanmiguel](https://community.modx.com/u/ysanmiguel)\
**Post date:** [April 9, 2024, 2:00pm UTC](https://community.modx.com/t/migx-database-csv-export-edit-titles-and-order-solved/7672/5 "2024-04-09T14:00:31Z")

</div>

Well just to inform that I solved my problem.  
In my case it’s only 1 table I need to export so I followed @halftrainedharry advice and modified the existing processor, in this case was: `core/components/migx/processors/mgr/default/exportcsv.php`

and the code I modified is:

```auto
    if ($header_row) {
        foreach ($array[0] as $key => $val) {
            //Escaping quotes.
            $key = str_replace($qut, "$qut$qut", $key);
            
            // ******** FIND AND REPLACE NAMES
            if ($key == "email") {
                $key = "Email";
            } elseif ($key == "firstname") {
                $key = "First Name";
            }
            // ******** FIND AND REPLACE NAMES
            
            $output .= "$col_sep$qut$key$qut";
        }
        $output = substr($output, 1) . $row_sep;
    }

```

It works just perfect. The order of the columns I did it directly modifying the table because I needed to add 1 extra field, so I just did it from there.

But thanks as always, problem solved! 👍
