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
Use ColCaption array for CSV
Re: Use ColCaption array for CSV
With assist from viewtopic.php?t=3452, figured it out. In the tablename_init hook, add
Nice and easy.
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;
Re: Use ColCaption array for CSV
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;