Set current DateTime variable after insert, update or reload

QuestionsSet current DateTime variable after insert, update or reload
Matt asked 1 year ago

Hi Abu,

 

I have a field to capture the last modified DateTime, this works fine but the current datetime value will only change when the html page is reloaded.  After an update/insert/delete or clicking the in-grid refresh button the datetime value doesn’t change.  I’ve tried to use an event to reload the page but it’s throwing a 404 error.  Any clues?  Thanks mate.

 

MY COLUMN CODE WHICE CREATES A DROPDOWN WITH A SINGLE ENTRY

$col = array();
$col[“title”] = “<p class=’rotate’>Last Modified Datetime</p>”;
$col[“name”] = “disd_lastmodifieddatetime”;
$col[“fixed”] = true;
$col[“editable”] = true;$col[“width”] = “120”;
$col[“align”] = “center”;
$col[“edittype”] = “select”;
$str = date(“Y-m-d H:i:s”).’|’.date(“Y-m-d H:i:s”);
$col[“editoptions”] = array(“value” => $str, “separator” => “|”, “delimiter” => “;”);
$col[“formatter”] = “datetime”;
$col[“formatoptions”] = array(“srcformat”=>’Y-m-d H:i:s’,”newformat”=>’d/m/Y H:i:s’);
$cols[] = $col;

 

THE EVENT CODE I TRIED BUT NOT WORKING

$e[“on_after_insert”] = array(“after_insert”, null, true);
$g->set_events($e);
function after_insert($data){
location.reload();
}

 

2 Answers
Abu Ghufran Staff answered 1 year ago

Hello,

If you wish to save last modified time while add/update operations, you can use build in mysql feature.

https://dev.mysql.com/doc/refman/8.0/en/timestamp-initialization.html

I really don’t understand how and where you are going to save update time on deleting that row.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Matt answered 1 year ago

Hi Abu,

 

Thank you very much, I never thought to do it like that but it’s quite obvious now.  I’ve been able to get it to work by changing $col[“editable”] = false in the grids lastmodifieddatetime field and setting the DATETIME field in the database to have default value “CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP”

This works as intended, thanks.

 

Matt

 

Your Answer

20 + 2 =

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?