Hi Abu. I have a problem when modifying a record. Record field empty . Thank you
$col = array();
$col["title"] = "Estado";
$col["name"] = "estado";
$col["edittype"] = "select"; // render as select
$col["editoptions"] = array("value"=>'A:Authorized;P:Pending; R:Rejected');
$col["formatter"] = "select";
$col["editrules"] = array("required"=>true);
$col["align"] = "center";
$col["width"] = "35";
$col["editable"] = true;
$col["show"] = array("list"=>true, "add"=>false, "edit"=>true, "view"=>true);
$cols[] = $col;
I am unable to understand the issue with this code.
If you can share complete grid code + screenshot, it would help.
You can email me at [email protected]
When I add a record, the field TipoEstado records it well. When modifying a record, the records it empty field codTipoEstado
CREATE TABLE IF NOT EXISTS `gen_tipogasto` (
`codTipoGasto` tinyint(4) NOT NULL,
`tipoGasto` varchar(50) NOT NULL,
`tipoGastoRed` varchar(20) NOT NULL,
`codTipoEstado` char(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
<?php
//include_once("../conn/seguridad.php");
include_once("../phpgrid/config.php");
include_once("../conn/funciones_generales.php");
//$codUsuario = $_SESSION['codUsuario'];
$themeid = "cupertino";
//list($agregar, $editar, $borrar) = PermisoUsuario($_SESSION["codUsuario"], $_SERVER["PHP_SELF"]);
function add_Gastos($data) {
global $g;
$Id = CodMax("gen_tipoGasto", "codTipoGasto");
$data["params"]["codTipoGasto"] = $Id;
$data["params"]["tipoGasto"] = strtoupper($data["params"]["tipoGasto"]);
}
function upd_Gastos($data) {
global $g;
$data["params"]["tipoGasto"] = strtoupper($data["params"]["tipoGasto"]);
}
// include and create object
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
// Database config file to be passed in phpgrid constructor
$db_conf = array("type" => PHPGRID_DBTYPE, "server" => PHPGRID_DBHOST, "user" => PHPGRID_DBUSER, "password" => PHPGRID_DBPASS, "database" => PHPGRID_DBNAME );
$g = new jqgrid($db_conf);
$opt["caption"] = "Gastos";
$opt["toolbar"] = "bottom";
$opt["add_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'440');
$opt["edit_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'440');
$g->set_options($opt);
$g->set_actions(array("add"=>$agregar, "edit"=>$editar, "bulkedit"=>false, "delete"=>$borrar, "rowactions"=>true, "autofilter" => true, "search" => "simple"));
$e["on_insert"] = array("add_Gastos", null, true);
$e["on_update"] = array("upd_Gastos", null, true);
$g->set_events($e);
// set table for CRUD operations
$g->table = "gen_tipogasto";
$col = array();
$col["title"] = "Id"; // Rótulo
$col["name"] = "codTipoGasto"; // Campo
$col["hidden"] = true;
$col["autoid"] = false;
$cols[] = $col;
$col = array();
$col["title"] = "Gasto"; // Rótulo
$col["name"] = "tipoGasto"; // Campo
$col["editable"] = true;
$col["editrules"] = array("required"=>true);
$col["editoptions"] = array("size"=>40);
$cols[] = $col;
$col = array();
$col["title"] = "Abreviatura"; // Rótulo
$col["name"] = "tipoGastoRed"; // Campo
$col["editable"] = true;
$col["editrules"] = array("required"=>true);
$cols[] = $col;
$col = array();
$col["title"] = "Estado";
$col["name"] = "codTipoEstado";
$col["edittype"] = "select"; // render as select
$col["editoptions"] = array("value"=>'A:Aprobado; P:Pendiente; R:Rechazado');
$col["formatter"] = "select";
$col["editable"] = true;
$col["editrules"] = array("required"=>true);
$col["align"] = "center";
$col["width"] = "35";
$cols[] = $col;
$g->set_columns($cols);
$out = $g->render("list1");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="../phpgrid/lib/js/themes/<?php echo $themeid ?>/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="../phpgrid/lib/js/jqgrid/css/ui.jqgrid.css"></link>
<script src="../phpgrid/lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../phpgrid/lib/js/jqgrid/js/i18n/grid.locale-es.js" type="text/javascript"></script>
<script src="../phpgrid/lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../phpgrid/lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
</head>
<body>
<div style="margin:10px">
<?php echo $out?>
</div>
</body>
</html>
Hi,
By reviewing your code, there is a space after ; which is making length to 2 char. And your database field length is char(1). Try removing it.
this:
$col["editoptions"] = array("value"=>'A:Aprobado; P:Pendiente; R:Rechazado');
with:
$col["editoptions"] = array("value"=>'A:Aprobado;P:Pendiente;R:Rechazado');