Ok,
I thought that saving a datetime in oracle was something more simple and widespread …
anyway, I’ve made this way:
- edit db_common.php at line 768:
(...)
protected function update_query($data,$request){
(...)
// ORIGINAL
// $step_value = "'".$this->escape($data->get_value($step["name"]))."'";
// MODIFICATION
if ( strpos( strtoupper($data->get_value($step["name"])),'TO_DATE') === false ) {
$step_value = "'".$this->escape($data->get_value($step["name"]))."'";
} else {
$step_value = $data->get_value($step["name"]);
};
// END MODIFICATION
- Write a formatting function in the xxx.php page that is called by grid.load(“xxx.php”) and new dataProcessor ("xxx.php); like this:
require_once("../js/vendor/codebase/connector/grid_connector.php");//includes related connector file
require_once("../js/vendor/codebase/connector/options_connector.php");//includes related connector file
require_once("../js/vendor/codebase/connector/db_oracle.php");//includes related connector file
function formatting($row){
//formatting a specific datetime field
$data = $row->get_value("MYDATETIMEFIELD");
$row->set_value("MYDATETIMEFIELD","To_date('" . $data . "','DD/MM/YYYY HH24:MI:SS')");
};
$gridConn = new GridConnector($oraconn,"Oracle"); // connector initialization
$gridConn->enable_log("../logs/MaybeItWorks.log",true);
$statement = "Select id,To_Char(MyDateTimeField,'DD/MM/YYYY HH24:MI:SS') as MyDateTimeField from MyTable";
$gridConn->event->attach("beforeUpdate","formatting");
$gridConn->render_sql($statement,"ID","ID,MYDATETIMEFIELD");
So MyDateTimeField is displayed as DD/MM/YYYY HH24:MI:SS in the grid (you should use setColTypes(“ed”) )
Moreover, if you have a form linked to the grid I’ve used this trick:
put an hidden field in the form whith the date field and an empty calendar,
set the date of the calendar in onRowSelect of the grid to maintein it alligned
set the hidden field value whith the calendar value in onBeforeValidate event of the form.
var formStructure = [ (...)
{type: "calendar", name: "MYDATETIMEFIELD_CALENDAR", label: "FakeDate", dateFormat: "%d/%m/%Y %H:%i:%s", serverDateFormat: "%d/%m/%Y %H:%i:%s", enableTime: true, position: "absolute", inputTop: 70, inputLeft: 5, labelLeft: 5, labelTop: 50, labelWidth: 500},
{type: "hidden", name: "MYDATETIMEFIELD" },
];
(...)
myGrid.attachEvent("onRowSelect", function (id, ind) {
myForm.setItemValue("MYDATETIMEFIELD_CALENDAR", myForm.getItemValue("MYDATETIMEFIELD"));
});
myForm.attachEvent("onBeforeValidate", function (id, values){
// Copio il contenuto del calendario nel campo nascosto
var dhxCalendar = myForm.getCalendar("MYDATETIMEFIELD_CALENDAR");
var S = dhxCalendar.getFormatedDate("%d/%m/%Y %H:%i:%s");
myForm.setItemValue("MYDATETIMEFIELD", S);
return true;
});
It’s quite a dirty way, but it works.
Hope it helps,
Bye !