I’m using Grid4PHP in my project and I have an issue retrieving a data value.
In my table I have a data column:
data date
id int(11)
...other fields
Here my relevant code:
$db_conf = array(
"type" => PHPGRID_DBTYPE,
"server" => PHPGRID_DBHOST,
"user" => PHPGRID_DBUSER,
"password" => PHPGRID_DBPASS,
"database" => PHPGRID_DBNAME
);
$g = new jqgrid($db_conf);
function setup_options($g, $table, $title=null) :void {
$caption = $title;
if ($caption == null) $caption = str_replace("_", " ", $table);
$opt["caption"] = ucwords($caption);
$opt["forceFit"] = true;
$opt["rownumbers"] = true;
$opt["rownumWidth"] = 50;
$opt["autoresize"] = true;
$opt["autowidth"] = true;
$opt["resizable"] = false;
$opt["height"] = "100%";
$opt["globalsearch"] = true;
$opt["toolbar"] = "bottom";
$opt["toppager"] = false;
$opt["pgbuttons"] = true;
$opt["cellEdit"] = true;
$opt["reloadedit"] = true;
$g->table = $table;
$g->set_options($opt);
$g->set_actions(array(
"add" => true,
"delete" => true,
"edit" => true,
"autofilter" => true,
"search" => "simple",
"export_excel" => true,
"export_pdf" => true,
"export_csv" => true,
"export_html" => true,
));
}
function setup_table($g): void {
$col = array();
$col["name"] = "data";
$col["formatter"] = "date";
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y');
$cols[] = $col;
$col = array();
$col["title"] = " ";
$col["name"] = "more_actions";
$col["fixed"] = true;
$col["width"] = "40";
$col["align"] = "center";
$col["search"] = false;
$col["sortable"] = false;
$buttons_html="<a class="ui-custom-icon ui-icon ui-icon-locked" title="copy" href="javascript:void(0);" onclick="copy_to_fixed({data})"></a>";
$col["default"] = $buttons_html;
$cols[] = $col;
$g->set_columns($cols, true);
}
$g->select_command = "custom query";
setup_options($g, "mytable");
setup_table($g);
$table = $g->render("mytable");
?>
<?php include ('header.php'); ?>
<div class="container-fluid">
<div class="row flex-nowrap">
<?php include('navigation.php'); ?>
<div class="col py-3">
<?php echo $table ?>
</div>
</div>
</div>
<script>
function copy_to_fixed(data) {
console.log(data)
}
</script>
For example 2024-09-11 (as in the db) is shown as 11/09/2024 but the printed value is 2004. Should I use any conversion function to retrieve the actual value?
You need to sign in to view this answers