Forum
17:37
15/01/2010
I've a grid with a subgrid. I've enabled the 'add' and 'edit' options in the subgrid, show the form correctly but when clicked the save button the data are not saved in the database.
Why?
the grid code: gridavisos.php
<?php
require_once 'jq-config.php';
// include the jqGrid Class
require_once ABSPATH."jqGrid.php";
// include the driver class
require_once ABSPATH."jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// this table is 1252 encoded, so we need to tell the grid
// Set the table data source
$grid->setTable('clientes');
// set the ouput format to xml since json have problems
$grid->dataType = 'xml';
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('gridavisos.php');
// Set some grid options
$grid->setGridOptions(array("height"=>400,"hoverrows"=>true,"autowidth"=>true,"rowNum"=>20,"rowList"=>array(20,50,100),"sortname"=>"nombre"));
$grid->setColProperty("cif", array("width"=>90));
$grid->setColProperty("cp", array("width"=>45));
$grid->setColProperty("provincia", array("width"=>80));
$grid->setColProperty("telefono", array("width"=>60));
// We can hide some columns
$grid->setColProperty("id_cliente", array("hidden"=>true));
// set labels in the header
$grid->setColProperty("nombre", array("label"=>"Nombre"));
$grid->setColProperty("cif", array("label"=>"NIF"));
$grid->setColProperty("direccion", array("label"=>"Dirección"));
$grid->setColProperty("cp", array("label"=>"CP"));
$grid->setColProperty("poblacion", array("label"=>"Población"));
$grid->setColProperty("provincia", array("label"=>"Provincia"));
$grid->setColProperty("email", array("label"=>"Email"));
$grid->setColProperty("telefono", array("label"=>"Teléfono"));
// Enable toolbar searching
$grid->toolbarfilter = true;
$grid->setFilterOptions(array("stringResult"=>true));
$grid->setSubGridGrid("subgridavisos.php");
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>
the subgrid code: gridsubavisos.php
<?php
require_once 'jq-config.php';
// include the jqGrid Class
require_once ABSPATH."jqGrid.php";
// include the driver class
require_once ABSPATH."jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Get the needed parameters passed from the main grid
// By default we add to postData subgrid and rowid parameters in the main grid
$subtable = jqGridUtils::Strip($_REQUEST["subgrid"]);
$rowid = jqGridUtils::Strip($_REQUEST["rowid"]);
if(!$subtable && !$rowid) die("Missed parameters");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = "SELECT * FROM avisos WHERE id_cliente = ?";
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel(null,array(&$rowid));
// Set the url from where we obtain the data
$grid->setUrl('subgridavisos.php');
// Set some grid options
$grid->setGridOptions(array(
"hoverrows"=>true,"autowidth"=>true,
"rowNum"=>10,
"sortname"=>"id_aviso",
"height"=>70,
"postData"=>array("subgrid"=>$subtable,"rowid"=>$rowid)));
// Change some property of the field(s)
$grid->setColProperty("fecha", array(
"formatter"=>"date",
"formatoptions"=>array("srcformat"=>"Y-m-d","newformat"=>"d/m/Y"),
"search"=>false
)
);
$grid->setColProperty("fecha", array("width"=>15));
// We can hide some columns
//$grid->setColProperty("id_aviso", array("hidden"=>true));
//$grid->setColProperty("id_cliente", array("hidden"=>true));
// set labels in the header
$grid->setColProperty("fecha", array("label"=>"Fecha"));
$grid->setColProperty("descripcion", array("label"=>"Descripción"));
$grid->navigator = true;
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>true,"edit"=>true,"del"=>true,"view"=>true));
//config dialogs
$grid->setNavOptions('add',array("closeOnEscape"=>true,"closeAfterAdd"=>true,"reloadAfterSubmit"=>true));
$grid->setNavOptions('edit',array("checkOnSubmit"=>true,"closeOnEscape"=>true,"closeAfterEdit"=>true,"reloadAfterSubmit"=>true));
$grid->setNavOptions('view',array("closeOnEscape"=>true));
// Enjoy
$subtable = $subtable."_t";
$pager = $subtable."_p";
$grid->renderGrid($subtable,$pager, true, null, array(&$rowid), true,true);
$conn = null;
?>
database:
table: clientes
id_cliente, nombre, cif, direccion, cp, poblacion, provincia, email, telefono
table: avisos
id_aviso, id_cliente, fecha, descripcion
11:55
Moderators
30/10/2007
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
45 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66