Page 1 of 1

How to save selected column to export CSV

Posted: 2024-08-10 02:09
by soewandi
I want to save selected column (e.g. column 1, 3, 5) when export to CSV File. AG default always save all fields. Please help me, and many thanks for your help.

My regards,
Soewandi

Re: How to save selected column to export CSV

Posted: 2024-08-11 00:40
by zibrahim
Hi there,
You can customise the columns etc by specifying the query in the hooks/TABLENAME.php file.
Scroll down to the bottom, you should see the line like this...

Code: Select all

function TABLENAME_csv($query, $memberInfo, &$args) {
Then, put your query inside the curly bracket above the return $query; statement
Example:

Code: Select all

function booking_csv($query, $memberInfo, &$args) {
	$query = "SELECT `booking`.`id` AS booking_id, `customer`.`name` AS customer FROM `booking` LEFT JOIN `customer` ON `booking`.`customer_id` = `customer`.`id` WHERE 1 = 1 ORDER BY `booking`.`id`";

	return $query;
}
If nothing happen after you click the Save CSV button, you might want to check if there is any error in your query under Admin Area -> Utilities -> Query logs

Have a nice day.

Re: How to save selected column to export CSV

Posted: 2024-08-11 11:10
by soewandi
Yes, you exactly helped me. :D Many thanks Mr. Zibrahim

My warm regards
soewandi