Foros del Web » Programando para Internet » Jquery »

jqueryGrid y json

Estas en el tema de jqueryGrid y json en el foro de Jquery en Foros del Web. Hola, estoy intentando hacer un grid cargando datos con json, pero parece que no puede cargarlos. Os muestro mi código jquery: Código: jQuery("#listadoGrid").jqGrid({ url:'/AODB2/maintenance/gate/NewGate.action?accion=listar', datatype: ...
  #1 (permalink)  
Antiguo 11/05/2011, 04:05
 
Fecha de Ingreso: diciembre-2008
Mensajes: 233
Antigüedad: 15 años, 4 meses
Puntos: 1
jqueryGrid y json

Hola, estoy intentando hacer un grid cargando datos con json, pero parece que no puede cargarlos. Os muestro mi código jquery:

Código:
jQuery("#listadoGrid").jqGrid({
				   	url:'/AODB2/maintenance/gate/NewGate.action?accion=listar',
					datatype: "json",
				   	colNames:['Codigo','Nombre', 'Descripcion', 'Tipo de puerta','Zona','Stand'],
				   	colModel:[
				   		{name:'Codigo',index:'Codigo', width:110, editable:false, editoptions:{readonly:true,size:10}},
				   		{name:'Nombre',index:'Nombre', width:160, editable:true, editoptions:{size:10}},
				   		{name:'Descripcion',index:'Descripcion', width:200, sortable: false, editable: true, edittype:"textarea", editoptions:{rows:"2",cols:"20"}},
				   		{name:'TipoPuerta',index:'TipoPuerta', width:120, align:"right", editable:true, editoptions:{size:10}},		   		
						{name:'Zona',index:'Zona',width:110,align:'center',editable:true,edittype:"checkbox",editoptions:{value:"Yes:No"}},
						{name:'Stand',index:'Stand', width:120, align:"right", editable:true, editoptions:{size:10}}		
				   	],
				   	rowNum:2,
				   	rowList:[2,4,8],
				   	pager: '#pageGrid',
				   	sortname: 'Nombre',
				    viewrecords: true,
				    sortorder: "desc",
				    caption: "Puertas"
				    //editurl:'/AODB2/maintenance/gate/EditDialogGate.action?', //para el cuadro de dialogo
					//height:280  //para el cuadro de dialogo
					
				});
				jQuery("#listadoGrid").jqGrid('navGrid','#pageGrid',{edit:false,add:false,del:false});
y el fichero json que me devuelve la url '/AODB2/maintenance/gate/NewGate.action?accion=listar' :

Código HTML:
<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<s:set name="theme" value="'simple'" scope="page"/>

{
	 "total": "1", 
 	 "page": "1", 
  	 "records": "4",
  	 "rows" :[
		<s:iterator value="%{gateListBck}" status="gateStatus">
		{
			"Codigo":"<s:property value="%{idGateList}"/>",
			"Nombre":"<s:property value="%{nameList}"/>",
			"Descripcion":"<s:property value="%{descriptionList}"/>",
			"TipoPuerta":"<s:property value="%{nameGateTypeList}"/>",
			"Zona":"<s:property value="%{nameZoneGateList}"/>",
			"Stand":"<s:property value="%{standCodeList}"/>"			
		}
		<s:if test="!#gateStatus.last">,</s:if>
		</s:iterator>
	]
}
Parece que la estructura es correcta, pero no me carga nada. ¿Alguna idea de cual es el problema? Estoy usando la versión 4.0 de jqueryGrid.

Muchas gracias, un saludo
  #2 (permalink)  
Antiguo 12/05/2011, 04:08
 
Fecha de Ingreso: diciembre-2008
Mensajes: 233
Antigüedad: 15 años, 4 meses
Puntos: 1
Respuesta: jqueryGrid y json

Al final lo he solucionado de la siguiente manera:

primero, he cambiado a la versión 3.8 en lugar de la 4.0

el código jquery ha quedado como sigue:
Código:
jQuery("#listadoGrid").jqGrid({
				   	url:'/AODB2/maintenance/gate/NewGate.action?accion=listar',
					datatype: "json",
				   	colNames:['Codigo','Nombre', 'Descripcion', 'TipoPuerta','Zona','Stand'],
				   	colModel:[
				   		{name:'Codigo',index:'Codigo', width:110, align:'center',editoptions:{readonly:true,size:10}},
				   		{name:'Nombre',index:'Nombre', width:160, align:'center'},
				   		{name:'Descripcion',index:'Descripcion', width:200, align:'center'},
				   		{name:'TipoPuerta',index:'TipoPuerta', width:120, align:'center'},		   		
						{name:'Zona',index:'Zona',width:110,align:'center'},
						{name:'Stand',index:'Stand', width:120, align:'center'}		
				   	],
				   	rowNum:2,
				   	rowTotal: 5,
				   	rowList:[2,4,8],
				   	pager: '#pageGrid',
				   	sortname: 'Nombre',
				    	viewrecords: true,
				    	sortorder: "desc",				    	
				    	jsonReader: {
						repeatitems : false,
						id: "0"						
					},

				    	caption: "Puertas",
				    	//editurl:'/AODB2/maintenance/gate/...', es donde va al dar al submit en las ventanitas
				    	pgbuttons: true,
				    	height: '100%'
				    	
    				    
					
				});

				jQuery("#listadoGrid").jqGrid('navGrid','#pageGrid',
					//options
					{ 
					view: true,
				
					     search : {
					     	    
						     caption: "Alohomora...",
						     Find: "Find",
						     Reset: "Reset",
						     odata : ['equal', 'not equal'],
						     groupOps: [ { op: "AND", text: "all" }, { op: "OR", text: "any" } ],
						     matchText: " match",
						     rulesText: " rules",
					     	     multipleSearch : true
						   },
						edit : true,
						del : {
						    caption: "Delete",
						    msg: "Delete selected record(s)?",
						    bSubmit: "Delete",
						    bCancel: "Cancel"
						  },
						nav : {
						    edittext: "",
						    edittitle: "Edit selected row",
						    addtext:"",
						    addtitle: "Add new row",
						    deltext: "",
						    deltitle: "Delete selected row",
						    searchtext: "",
						    searchtitle: "Find records",
						    refreshtext: "",
						    refreshtitle: "Reload Grid",
						    alertcap: "Warning",
						    alerttext: "Please, select row",
						    viewtext: "",
						    viewtitle: "View selected row"	    					    
					  	}
					},
					{ // edit options
						editCaption: "Editando que es gerundio",
						height:400,
						reloadAfterSubmit:false,
						checkOnSubmit : true
					},
					{height:280,reloadAfterSubmit:false}, // add options
					{reloadAfterSubmit:false}, // del options
					{} // search options					
				);
y el json:
Código HTML:
<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<s:set name="theme" value="'simple'" scope="page"/>

{	
	"page": 1,
	"total": 3,
	"records":5, 
  	 "rows":[
		<s:iterator value="%{gateListBck}" status="gateStatus">
		{
			"Codigo":"<s:property value="%{idGateList}"/>",
			"Nombre":"<s:property value="%{nameList}"/>",
			"Descripcion":"<s:property value="%{descriptionList}"/>",
			"TipoPuerta":"<s:property value="%{nameGateTypeList}"/>",
			"Zona":"<s:property value="%{nameZoneGateList}"/>",
			"Stand":"<s:property value="%{standCodeList}"/>"			
		}
		<s:if test="!#gateStatus.last">,</s:if>
		</s:iterator>
	]
}
pero ahora no me funcionan los botones de la barra del navegador. Es decir, sí funcionan, pero cuando me aparece por ejemplo la ventana de editar, no me saca ningún campo, ningún formulario, solamente los botones de submit y close. ¿Me falta algo por rellenar? Muchas gracias, un saludo
  #3 (permalink)  
Antiguo 17/05/2011, 04:35
 
Fecha de Ingreso: diciembre-2008
Mensajes: 233
Antigüedad: 15 años, 4 meses
Puntos: 1
Respuesta: jqueryGrid y json

Al final me faltaba la opcion editable:true en colNames. Después de incluírla ya puedo ver los campos.

Un saludo

Etiquetas: javascript, json
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:16.