Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Master Detail not work
11/08/2010
19:28
Avatar
larosal
Member
Members
Forum Posts: 21
Member Since:
13/07/2010
sp_UserOfflineSmall Offline
Hi,

Could you help me?, I am new to jQuery and jqGrid.

I have a lot of time with this, my problem is: the key does not pass to the grid master to detail, in my PHP code, I will always get one empty

Sorry, for my English,

Thank a lot

Here is a portion of code,

jQuery(document).ready(function(){
jQuery("#req_p").jqGrid({
url:'solic_almac_p.php',
datatype:'json',
mtype:'GET',
colNames:['No.Requisición','Área Solicitante','Fecha Solicitud','Cargo Solicitante'],
colModel:[
{name:'no_requisicion',index:'no_requisicion',key:true,width:100,align:'right'},
{name:'area_solicitante',index:'area_solicitante',width:100,align:'left'},
{name:'fec_solicitud',index:'fec_solicitud',width:90,align:'right'},
{name:'cargo_solicitante',index:'cargo_solicitante',width:100,align:'left'}
],
pager:'#req_p1',
rowNum:10,
rowList:[10,20,30],
sortname:'no_requisicion',
sortorder:'asc',
viewrecords:true,
multiselect:false,
caption: "SOLICITUD DE MATERIAL",
width:775,
height:'auto',
onSelectRow: function(no_requisicion) {
if(no_requisicion == null) {
no_requisicion=0;
if(jQuery("#req_h1″).jqGrid('getGridParam','records') >0 )
{
jQuery("#req_h1″).jqGrid('setGridParam',{url:'solic_almac_h.php?id='+no_requisicion,page:1});
jQuery("#req_h1″).trigger("reloadGrid");
}
} else {
jQuery("#req_h1″).jqGrid('setGridParam',{url:'solic_almac_h.php?id='+no_requisicion,page:1});
jQuery("#req_h1″).trigger("reloadGrid");
}
}
});
jQuery("#req_p").jqGrid('navGrid','#req_p1',{add:true,edit:true,del:true});

jQuery("#req_h").jqGrid({
url:'solic_almac_h.php',
datatype: "json",
colNames:['No.','Desc.Artículo', 'U.Medida','Solic.','$ Unitario','$ Total'],
colModel:[
{name:'no_prog',index:'no_prog', width:40, align:'right',resizable:false,editable:false,editoptions:{readonly:true,size:10}},
{name:'articulo',index:'articulo', width:300, align:'left',editable:true,editoptions:{size:25}},
{name:'unidad_medida',index:'unidad_medida', width:100, align:'left',resizable:false,editable:true,editoptions:{size:10}},
{name:'solicitado',index:'solicitado', width:60, align:'right',resizable:false,editable:true,editoptions:{size:10}},
{name:'costo_unitario',index:'costo_unitario',width:90, align:'right',resizable:false,editable:false},
{name:'costo_total',index:'costo_total',width:100, align:'right', editable:false},
],
rowNum:5,
rowList:[5,10,20],
pager:'#req_h1',
sortname:'no_prog',
viewrecords:true,
sortorder:'asc',
caption:'Detalle',
height:'auto'
});
jQuery("#req_h").jqGrid('navGrid','#req_h1',
{}, //options
{height:280,reloadAfterSubmit:false}, // edit options
{height:280,reloadAfterSubmit:false}, // add options
{reloadAfterSubmit:false}, // del options
{} // search options
);
})

Here is the master PHP code,

<?php
include_once ("conexion.php");

// to the url parameter are added 4 parameters as described in colModel
// we should get these parameters to construct the needed query
// Since we specify in the options of the grid that we will use a GET method
// we should use the appropriate command to obtain the parameters.
// In our case this is $_GET. If we specify that we want to use post
// we should use $_POST. Maybe the better way is to use $_REQUEST, which
// contain both the GET and POST variables. For more information refer to php documentation.
// Get the requested page. By default grid sets this to 1.
include("php/JSON.php");

$json = new Services_JSON();

$page = $_GET['page'];

// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_GET['rows'];

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];

// sorting order - at first time sortorder
$sord = $_GET['sord'];

// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;

// connect to the MySQL database server and the database, too
$Conexion=new Conexion();
$Conexion->getConexion();

// calculate the number of rows for the query. We need this to paging the result
$result = mysql_query("SELECT COUNT(*) AS count FROM requisicion_p");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];

// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}

// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;

// calculate the starting position of the rows
$start = $limit*$page - $limit;

// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;

// the actual query for the grid data
$query="SELECT no_requisicion,";
$query.="desc_area_solicitante as area_solicitante,";
$query.="DATE_FORMAT(fec_solicitud,'%d/%m/%Y') as fec_solicitud,";
$query.="desc_cargo_solicitante as cargo_solicitante ";
$query.="FROM requisicion_p,area_solicitante,cargo_solicitante ";
$query.="WHERE no_area_solicitante=area_solicitante ";
$query.="AND no_cargo_solicitante=cargo_solicitante ";
$query.="ORDER BY $sidx $sord LIMIT $start,$limit";
$result = mysql_query( $query ) or die("No se puede ejecutar la sentencia.".mysql_error());

// constructing a JSON
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$response->rows[$i]['no_requisicion']=$row[no_requisicion];
$response->rows[$i]['cell']=array($row[no_requisicion],$row[area_solicitante],$row[fec_solicitud],$row[cargo_solicitante]);
$i++;
}

//Cierra la conexión
$Conexion->Close();

// return the formated data
echo $json->encode($response);
?>

This is Detail PHP code,

<?php
include_once ("conexion.php");

// to the url parameter are added 4 parameters as described in colModel
// we should get these parameters to construct the needed query
// Since we specify in the options of the grid that we will use a GET method
// we should use the appropriate command to obtain the parameters.
// In our case this is $_GET. If we specify that we want to use post
// we should use $_POST. Maybe the better way is to use $_REQUEST, which
// contain both the GET and POST variables. For more information refer to php documentation.
// Get the requested page. By default grid sets this to 1.
include("php/JSON.php");

$json = new Services_JSON();

$page = $_GET['page'];

// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_GET['rows'];

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];

// sorting order - at first time sortorder
$sord = $_GET['sord'];

// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;

//Conexión a MySQL y a la BD
$Conexion=new Conexion();
$Conexion->getConexion();

// calculate the number of rows for the query. We need this to paging the result
$no_requisicion = (isset($_REQUEST['id']) ? trim($_REQUEST['id'] ): null);
if ($no_requisicion!=null){
$result = mysql_query("SELECT COUNT(*) AS count FROM requisicion_h WHERE no_requisicion = $no_requisicion");
}
else{
$result = mysql_query("SELECT COUNT(*) AS count FROM requisicion_h");
}
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];

// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}

// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;

// calculate the starting position of the rows
$start = $limit*$page - $limit; // do not put $limit*($page - 1)

// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if ($start<0) $start = 0;

// the actual query for the grid data
$query="SELECT no_prog,desc_articulo as articulo,desc_unidad_medida as unidad_medida,solicitado,precio as costo_unitario, ";
$query.="solicitado*precio as costo_total ";
$query.="FROM requisicion_h,articulos,unidad_medida ";
$query.="WHERE articulo=no_articulo ";
$query.="AND unidad_medida=no_unidad_medida ";

if ($no_requisicion!=null){
$query.="AND no_requisicion=$no_requisicion ";
}
$query.="ORDER BY $sidx $sord LIMIT $start, $limit";
$result = mysql_query($query) or die("No se puede ejecutar la sentencia.".mysql_error());

// constructing a JSON
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$response->rows[$i]['no_prog']=$row[no_prog];
$response->rows[$i]['cell']=array($row[no_prog],$row[articulo],$row[unidad_medida],$row[solicitado],$row[costo_unitario],$row[costo_total]);
$i++;
}

//Cierra la conexión
$Conexion->Close();

// return the formated data
echo $json->encode($response);
?>

Thanks a lot

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
72 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information