-
-
Save raultorner/7d6d1d6675c41ee4f9798216fef3753c to your computer and use it in GitHub Desktop.
phpGrid Master Detail (Problem not showing rows on detail grid)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ERP Speedsix | |
* | |
* @author Raúl Torner Martinell - Speedsix | |
* @version 1.0.0 | |
*/ | |
include_once("config.php"); | |
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); | |
$grid["caption"] = "Logística"; | |
$grid["loadtext"] = "Cargando..."; | |
$grid["toolbar"] = "bottom"; | |
$grid["autowidth"] = false; | |
$grid["shrinkToFit"] = false; | |
$grid["width"] = "1000"; | |
$grid["hidegrid"] = true; | |
$grid["responsive"] = true; | |
//$grid["globalsearch"] = true; | |
//$grid["viewrecords"] = true; | |
$grid["rownumbers"] = true; | |
$grid["rownumWidth"] = "30"; | |
$grid["altRows"] = true; | |
$grid["multiselect"] = true; | |
$grid["multiboxonly"] = true; // keep multiselect only by checkbox, otherwise single selection | |
$grid["scroll"] = true; // mostramos scroll infinito o paginación | |
$grid["pgbuttons"] = true; | |
//$grid["form"]["nav"] = true; | |
$grid["tooltip"] = true; | |
$grid["reloadedit"] = true; | |
//$grid["footerrow"] = false; | |
//$grid["loadComplete"] = "function(){ load(); }"; | |
// export XLS file | |
/** | |
// export to excel parameters - range could be "all" or "filtered" | |
$grid["export_excel"] = array("format"=>"xlsx", "filename"=>"Logistica", "sheetname"=>"Registro de logística"); | |
$grid["export_excel"]["range"] = "filtered"; // or "all" | |
// export CSV file | |
$grid["export_csv"] = array("format"=>"csv", "filename"=>"Logistica", "sheetname"=>"Registro de logística"); | |
// export PDF file | |
$grid["export_pdf"] = array("format"=>"pdf", "filename"=>"Logistica", "heading"=>"Registro de logística", "orientation"=>"landscape"); | |
**/ | |
$grid["sortname"] = 'FECHAM'; | |
$grid["sortorder"] = "desc"; | |
$grid["detail_grid_id"] = "listsc2"; | |
$grid["subgridparams"] = "NDOC, CCLIE"; | |
$g->set_options($grid); | |
$g->select_command = "SELECT FECHAM, FECHA, CDESC, CCLIE, CNOM, (SELECT CONCAT(CDOM, ', ', CPOB, ' ', CCP, ' ', CPROV, ', ', CPAIS)) AS DOMICILIO, FECHA2, TLF1, EMAIL, COBS, (SELECT RIGHT(CDESC, 8)) AS NDOC | |
FROM dglog | |
WHERE SWFIN = 0 | |
"; | |
$g->table = "dglog"; | |
$cols = array(); | |
$col = array(); | |
$col["title"] = "Fecha"; // Título de la columna | |
$col["name"] = "FECHAM"; // Nombre del campo de la BBDD | |
$col["width"] = "100"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"] = array("date"=>true, "readonly" => true); // Validación: fecha + readOnly | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Fecha Doc."; // Título de la columna | |
$col["name"] = "FECHA"; // Nombre del campo de la BBDD | |
$col["width"] = "100"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"] = array("date"=>true, "readonly" => true); // Validación: fecha + readOnly | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Documento"; // Título de la columna | |
$col["name"] = "CDESC"; // Nombre del campo de la BBDD | |
$col["width"] = "200"; // Ancho de la celda | |
$col["align"] = "left"; // Alineamiento de texto | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "N. Documento"; // Título de la columna | |
$col["name"] = "NDOC"; // Nombre del campo de la BBDD | |
$col["width"] = "100"; // Ancho de la celda | |
$col["align"] = "left"; // Alineamiento de texto | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Cd."; // Título de la columna | |
$col["name"] = "CCLIE"; // Nombre del campo de la BBDD | |
$col["width"] = "100"; // Ancho de la celda | |
$col["align"] = "left"; // Alineamiento de texto | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Nombre"; // Título de la columna | |
$col["name"] = "CNOM"; // Nombre del campo de la BBDD | |
$col["width"] = "300"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Domicilio"; // Título de la columna | |
$col["name"] = "DOMICILIO"; // Nombre del campo de la BBDD | |
$col["width"] = "400"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Fecha Envio"; // Título de la columna | |
$col["name"] = "FECHA2"; // Nombre del campo de la BBDD | |
$col["width"] = "100"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"] = array("date"=>true, "readonly" => true); // Validación: fecha + readOnly | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Teléfono"; // Título de la columna | |
$col["name"] = "TLF1"; // Nombre del campo de la BBDD | |
$col["width"] = "150"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "E-mail"; // Título de la columna | |
$col["name"] = "EMAIL"; // Nombre del campo de la BBDD | |
$col["width"] = "200"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"] = array("email"=>true, "readonly" => true); // Validación: e-mail + readOnly | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Observaciones"; // Título de la columna | |
$col["name"] = "COBS"; // Nombre del campo de la BBDD | |
$col["width"] = "350"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$col["edittype"] = "textarea"; // render as textarea on edit | |
$col["editoptions"] = array("rows"=>6, "cols"=>26); // with these attributes | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Action"; | |
$col["name"] = "act"; | |
$col["hidden"] = true; | |
$col["hidedlg"] = true; | |
$cols[] = $col; | |
$g->set_columns($cols); | |
$g->set_actions(array( | |
"add"=>true, // añadir | |
"edit"=>true, // editar | |
"delete"=>false, // borrar | |
"view"=>true, | |
//"clone"=>false, // duplicar | |
//"bulkedit"=>false, // edición multiple | |
//"import"=>false, // importar | |
//"inlineadd"=>false, | |
//"export_excel"=>true, // exportar a excel | |
//"export_pdf"=>true, // exportar a pdf | |
//"export_csv"=>true, // exportar a csv | |
//"showhidecolumns"=>true, //columnas | |
//"rowactions"=>true, //acciones de fila | |
//"autofilter" => true, // autofiltro para busqueda | |
"search" => "advance" // busqueda avanzada | |
) | |
); | |
$out_master = $g->render("listsc"); | |
$db_conf = array( | |
"type" => PHPGRID_DBTYPE, | |
"server" => PHPGRID_DBHOST, | |
"user" => PHPGRID_DBUSER, | |
"password" => PHPGRID_DBPASS, | |
"database" => PHPGRID_DBNAME | |
); | |
$g = new jqgrid($db_conf); | |
$docu = $_GET["NDOC"]; | |
$codCliente = intval($_GET["CCLIE"]); | |
$grid["datatype"] = "local"; | |
$grid["caption"] = "Detalle"; | |
$grid["loadtext"] = "Cargando..."; | |
$grid["toolbar"] = "none"; | |
$grid["autowidth"] = false; | |
$grid["shrinkToFit"] = false; | |
$grid["width"] = "1000"; | |
$grid["height"] = "200"; | |
$grid["hidegrid"] = true; | |
$grid["responsive"] = true; | |
//$grid["globalsearch"] = true; | |
//$grid["viewrecords"] = true; | |
$grid["rownumbers"] = true; | |
$grid["rownumWidth"] = "30"; | |
$grid["altRows"] = true; | |
$grid["multiselect"] = true; | |
$grid["scroll"] = true; // mostramos scroll infinito o paginación | |
$grid["pgbuttons"] = true; | |
//$grid["form"]["nav"] = true; | |
$grid["tooltip"] = true; | |
$grid["reloadedit"] = true; | |
//$grid["footerrow"] = false; | |
//$grid["loadComplete"] = "function(){ load(); }"; | |
// fill detail grid add dialog with master grid id | |
$grid["add_options"]["afterShowForm"] = 'function() { var selr = jQuery("#listsc").jqGrid("getGridParam","selrow"); var n = jQuery("#listsc").jqGrid("getCell",selr,"name"); jQuery("#CODIGO").val( n ) }'; | |
// reload master after detail update | |
$grid["onAfterSave"] = "function(){ jQuery('#listsc').trigger('reloadGrid',[{current:true}]); }"; | |
$g->set_options($grid); | |
$g->select_command = "SELECT CODIGO, CARTICULO, TEXTO, CANTIDAD | |
FROM dgalb | |
WHERE CODIGO = $codCliente | |
AND NUMEROP = $docu | |
"; | |
$g->table = "dgalb"; | |
$cols = array(); | |
$col = array(); | |
$col["title"] = "Código"; // Título de la columna | |
$col["name"] = "CARTICULO"; // Nombre del campo de la BBDD | |
$col["width"] = "150"; // Ancho de la celda | |
$col["align"] = "left"; // Alineamiento de texto | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Docu N"; // Título de la columna | |
$col["name"] = "Docu"; // Nombre del campo de la BBDD | |
$col["width"] = "100"; // Ancho de la celda | |
$col["align"] = "left"; // Alineamiento de texto | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Descripción"; // Título de la columna | |
$col["name"] = "TEXTO"; // Nombre del campo de la BBDD | |
$col["width"] = "250"; // Ancho de la celda | |
$col["align"] = "left"; // Alineamiento de texto | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Cantidad"; // Título de la columna | |
$col["name"] = "CANTIDAD"; // Nombre del campo de la BBDD | |
$col["width"] = "100"; // Ancho de la celda | |
$col["editable"] = true; // Posibilidad de edición | |
$col["editrules"]["readonly"] = true; | |
$cols[] = $col; | |
$g->set_columns($cols); | |
$g->set_actions(array( | |
"add"=>false, // añadir | |
"edit"=>false, // editar | |
"delete"=>false, // borrar | |
"view"=>true, | |
//"clone"=>false, // duplicar | |
//"bulkedit"=>false, // edición multiple | |
//"import"=>false, // importar | |
//"inlineadd"=>false, | |
"export_excel"=>true, // exportar a excel | |
"export_pdf"=>true, // exportar a pdf | |
"export_csv"=>true, // exportar a csv | |
//"showhidecolumns"=>true, //columnas | |
"rowactions"=>false, //acciones de fila | |
"autofilter" => true, // autofiltro para busqueda | |
"search" => false // busqueda avanzada | |
) | |
); | |
$out_detail = $g->render("listsc2"); | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" type="text/css" media="all" href="../assets/css/style_speedsix.css" /> | |
<link rel="stylesheet" type="text/css" media="screen" href="../tablas/lib/js/themes/base/jquery-ui.custom.css" /> | |
<link rel="stylesheet" type="text/css" media="screen" href="../tablas/lib/js/jqgrid/css/ui.jqgrid.css" /> | |
<link rel="stylesheet" type="text/css" media="screen" href="../tablas/bootstrap/css/bootstrap3.min.css" /> | |
<style> | |
body { | |
padding-top: -40px; | |
padding-bottom: 0; | |
} | |
</style> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" /> | |
<link href="https://gitcdn.xyz/repo/wenzhixin/multiple-select/master/multiple-select.css" rel="stylesheet" /> | |
<script src="../tablas/lib/js/jquery.min.js" type="text/javascript"></script> | |
<script src="../tablas/lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> | |
<script src="../tablas/lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script> | |
<script src="https://kit.fontawesome.com/c828e66cf9.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script> | |
<script src="https://gitcdn.xyz/repo/wenzhixin/multiple-select/master/multiple-select.js"></script> | |
<script src="../tablas/lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script> | |
<!-- to enable spanish --> | |
<script src="../tablas/lib/js/jqgrid/js/i18n/grid.locale-es.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<div class="card mb-3 tabla-phpGrid"> | |
<div id="botones-adicionales-tabla" class="card-header-tab card-header"> | |
</div> | |
<div> | |
<?php echo $out_master?> | |
</div> | |
<br> | |
<div> | |
<?php echo $out_detail?> | |
</div> | |
<script> | |
$.jgrid.nav.addtext = "Añadir"; | |
$.jgrid.nav.edittext = "Editar"; | |
$.jgrid.nav.deltext = "Borrar"; | |
$.jgrid.nav.clone = "Duplicar"; | |
$.jgrid.nav.saveRow = "Guardar fila"; | |
$.jgrid.nav.restoreRow = "Restaurar fila"; | |
$.jgrid.nav.import = "Importar"; | |
$.jgrid.nav.Import = "Importar"; | |
$.jgrid.nav.export = "Exportar"; | |
$.jgrid.nav.Export = "Exportar"; | |
$.jgrid.nav.viewtext = "Ver"; | |
$.jgrid.nav.searchtext = "Buscar"; | |
$.jgrid.nav.refreshtext = "Refrescar"; | |
$.jgrid.nav.showhidecol = "Selecciona las columnas a mostrar"; | |
$.jgrid.nav.columns = "Columnas"; | |
$.jgrid.nav.Columns = "Columnas"; | |
$.jgrid.nav.bulkedit = "Edición multiple"; | |
$.jgrid.nav.bulkeditskip = "Nota: Los campos vacios se saltarán"; | |
$.jgrid.nav.saveRow = "Guardar fila"; | |
$.jgrid.nav.restoreRow = "Restaurar fila"; | |
function load() | |
{ | |
} | |
// ventana para edición | |
var opts = { | |
'ondblClickRow': function (id) { | |
jQuery(this).jqGrid('editGridRow', id, <?php echo json_encode_jsfunc($g->options["edit_options"])?>); | |
} | |
}; | |
</script> | |
</body> | |
</html> | |
<?php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment