Page 1 of 1

Use ColCaption array for CSV

Posted: 2020-08-19 22:06
by pfrumkin
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

Re: Use ColCaption array for CSV

Posted: 2020-08-19 22:39
by pfrumkin
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.

Re: Use ColCaption array for CSV

Posted: 2020-08-21 15:37
by pfrumkin
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;