Run SQL Command on Export Report Button Click

QuestionsRun SQL Command on Export Report Button Click
Mike Sheppard asked 11 months ago

I would like to run an SQL Update statement if a user clicks the Excel CSV Export Button, so I can track when the export has been ran.

Is this possible ?

 

Thanks

 

Mike

5 Answers
Abu Ghufran Staff answered 11 months ago

Hi,

You can try this code. $g is grid object. array 3rd index is set to true.

$e["on_export"] = array("custom_export", null, true);
$g->set_events($e);

// custom on_export callback function
function custom_export($param)
{
	$grid = $param["grid"];
	$grid->execute_query("UPDATE ....");
}
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Michael answered 11 months ago

Excellent and very straight forward, works perfectly!

 

Thank you for the quick response!

 

Mike

Michael answered 11 months ago

A follow-up question, sorry, I forgot to ask. Is there a way to pass-in the filter variables to the Function? I know how to pass parameters for add/edit, but if I Just have an inline filter for several columns for the export, can I add those filters?

Something like {$data[“params”][“filter_1”]} ?

Thanks again

Mike

Abu Ghufran Staff answered 11 months ago

You can debug $param inside the callback function, like

print_r($param); 
die;

$param array contains array of rows to be exported.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Michael answered 11 months ago

Thanks for the update!

That is another simple thing I overlooked.

 

Appreciate the feedback!

 

Mike

Your Answer

2 + 7 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?