Use ColCaption array for CSV

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Use ColCaption array for CSV

Post by pfrumkin » 2020-08-19 22:06

Hi,

When we save to CSV, it uses the table column names for the CSV column headers. Anyone know a slick way to use the colcaption array from the tablename_view.php file for the column headers?

I am hoping I don't have to build the query in the tablename_csv hook.

Thanks.

~Paul

AppGini 5.84

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Use ColCaption array for CSV

Post by pfrumkin » 2020-08-19 22:39

With assist from viewtopic.php?t=3452, figured it out. In the tablename_init hook, add

Code: Select all

		// set CSV column headers
		$oldFields = $options->QueryFieldsCSV;
		$i = 0;
     
		// loop through all fields
		foreach($oldFields as $field => $title) {
			$newFields[$field] = $options->ColCaption[$i];
			$i++;
		}
			 
		// now apply the modified fields
		$options->QueryFieldsCSV = $newFields;
Nice and easy.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Use ColCaption array for CSV

Post by pfrumkin » 2020-08-21 15:37

I updated to account for columns hidden on the TV

Code: Select all

    $CSVFields = $options->QueryFieldsCSV;
    $colIndex = 0;
    $colNumber = 0;

    // loop through all fields
    foreach ($CSVFields as $field => $title) {
        // Update column header
        if (($options->ColNumber[$colIndex] - 1) == $colNumber) {
            $newCSVFields[$field] = $options->ColCaption[$colIndex];
            $colIndex++;
        }
        else {
            $newCSVFields[$field] = $title;
        }
        $colNumber++;
    }
// now apply the modified fields
$options->QueryFieldsCSV = $newCSVFields;

Post Reply