早上好
很长一段时间后,我将回到php和javasvript,并且我使用jqGrid插入来创建网格。我用的很好,可以毫无问题地进行编辑和修改。当我想使用带有相关数据的表时,我可以找到问题。
该表是某些会员的费用,这些费用与会员本身有关。要编辑,请使用jqgrid表单。我试图进行选择,所以他们选择了会员,但我没有加载数据。 我给了它很多圈,我不知道我会发生什么。说我有点生锈。抱歉,如果发胖失败的话。
我放了我的代码。
Index.html:
<script type="text/javascript">
$(document).ready(function(){
jQuery("#tblCuotas").jqGrid({
url:'cargaCuotas.php',
editurl: "editCuotas.php",
datatype: 'json',
mtype: 'POST',
colModel:[
{
label: 'ID Cuota',
name: 'idCuota',
index:'idCuota',
width: 50,
key: true,
editable: true,
hidden: true
},
{
label: 'Num. Cuota',
name: 'NumD',
index:'NumD',
width: 50,
editable: true,
editoptions : { required: true, placeholder: "Número de Cuota requieredo"}
},
{
label: 'Num. Afiliado',
name: 'NumAfiliado',
index:'NumAfiliado',
width: 150,
editable: true,
edittype: 'select',
formatter:'select',
editoptions : { dataurl: 'afiliadosSelect.php' },
editrules : { required: true, placeholder: "Número de Cuota Afiliado"}
},
{
label: 'Nombre',
name: 'NOMBRE',
index:'NOMBRE',
width: 300,
editable: true
},
{
label: 'Cuota',
name: 'CUOTA',
index:'CUOTA',
width: 150,
editable: true,
editoptions : { required: true, placeholder: "Importe de la cuota requieredo"}
},
{
label: 'Mes',
name: 'MES',
index:'MES',
width: 120,
editable: true,
editoptions : { }
},
{
label: 'Año',
name: 'ANNO',
index:'ANNO',
width: 50,
editable: true,
editoptions : { }
},
{
label: 'Pago',
name: 'PAGO',
index:'PAGO',
width: 50,
editable: true,
edittype: 'select',
editoptions : { value: "Y:SI;N:NO" }
},
{
label: 'Forma Pago',
name: 'FormaPago',
index:'FormaPago',
width: 100,
editable: true,
editoptions : { }
}
],
loadonce: false,
width: window.innerWidth-20,
height: window.innerHeight-150,
pager: '#paginacion',
rowNum: 50,
rowList:[50,100,150],
sortname: 'NumD',
sortorder: 'asc',
viewrecords: true,
caption: 'CUOTAS'
});
jQuery("#tblCuotas").jqGrid('navGrid','#paginacion',
{edit:true,add:true,del:true},
// options for the Edit Dialog
{
html5Check : true,
editCaption: "The Edit Dialog",
recreateForm: true,
checkOnUpdate : true,
checkOnSubmit : true,
closeAfterEdit: true,
reloadAfterEdit:true,
reloadAfterSubmit:true,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
},
buttons : [
{
side : "right",
text : "Afiliado",
position : "first",
click : function( form, params, event) {
alert("Custom action in search form");
}
}
]
},
// options for the Add Dialog
{
closeAfterAdd: true,
html5Check : true,
recreateForm: true,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
},
// options for the Delete Dailog
{
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
});
});
</script>
afiliadosSelect.php:
<?php
include "../class/tAfiliados.php";
echo '<script>alert("Custom action in search form");</script>';
$oAfiliado = new tAfiliados(1, 0, 1, 1);
$respuesta = $oAfiliado->selectAfiliados();
echo $respuesta;
?>
tAfiliados.php:
<?php
include 'tMySQL.php';
class tAfiliados
{
public function selectAfiliados()
{
$oMySQL = new tMySQL();
if ($oMySQL->bConnect)
{
$cSQL ="SELECT COUNT(*) AS cuantos FROM afiliados WHERE borrado=0";
$this->fila = $oMySQL->countQuery($cSQL);
$this->cuantos = $this->fila['cuantos'];
$query = "SELECT idAfiliado, NumAfiliado, NOMBRE FROM afiliados WHERE borrado=0 ORDER BY NOMBRE";
$result = $oMySQL->GetQuery($query);
$response ='<select>';
$i=0;
while( $i <= $this->cuantos ) {
$response .= '<option value="'.$result[$i]['NumAfiliado'].'">'.$result[$i]['NOMBRE'].'</option>';
$i++;
}
$response .= '</select>';
}
$oMySQL->Close();
return $response;
}
}
?>
问候,非常感谢。
答案 0 :(得分:0)
请从您的代码中删除此行:
echo '<script>alert("Custom action in search form");</script>';
这导致加载数据时出现问题。数据应仅包含html数据,仅此而已。
此回声会导致数据无法加载到网格中。
更新:
对不起,刚才我看过您的代码。 JavaScript区分大小写。
请替换
editoptions : { dataurl: 'afiliadosSelect.php' },
使用
editoptions : { dataUrl: 'afiliadosSelect.php' },
UPDATE2
我已经用您的设置准备了一个演示,效果很好。这里is the link。请在网格所在的相关玩具中检查afiliadosSelect.php的路径是否正确。在这种情况下,您应该在控制台中出现错误。