Foros del Web » Programando para Internet » Javascript » Frameworks JS »

[SOLUCIONADO] Recargar 2 Grid con extjs

Estas en el tema de Recargar 2 Grid con extjs en el foro de Frameworks JS en Foros del Web. Buenas, vengo trabajando recientemente con extjs y e logrado que mediante un grid y un par de botones guarde elimine y modifique, hasta hay todo ...
  #1 (permalink)  
Antiguo 04/12/2013, 18:49
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Recargar 2 Grid con extjs

Buenas, vengo trabajando recientemente con extjs y e logrado que mediante un grid y un par de botones guarde elimine y modifique, hasta hay todo bien.

Ahora he hecho 2 tablas una alumno y una curso al hacer clic en el alumno se deberia mostrar los cursos en los que esta inscrito, he logrado mandar los datos al segundo grid pero el problema es que no lo recarga y por lo tanto los datos no se muestran(poniendo el id del alumno en la consulta si los carga).

Mi pregunta es como puedo hacer para refrescar los 2 grid automáticamente al ejecutar.

Selecciono el boton ver cursos y si una fila esta selecionada me manda los el id del curso y eso lo meto en una consulta.

Aqui ven como los datos llegan pero no recarga el grid.


Tengo este que me muestra los alumnos.

Código Javascript:
Ver original
  1. Ext.onReady(function(){
  2.   Ext.QuickTips.init();
  3.   var grid = 0;
  4.   // create the data store
  5.   var campos = Ext.data.Record.create([
  6.        {name: 'id'},
  7.        {name: 'nombre', type: 'string'},
  8.        {name: 'edad', type: 'number'},
  9.        {name: 'telefono', type: 'number'}
  10.   ]);    
  11.   var reader = new Ext.data.JsonReader({        
  12.          root: 'estudiantes2',
  13.          totalProperty: 'total',
  14.       },        
  15.       campos
  16.   );
  17.   var store = new Ext.data.GroupingStore({
  18.       proxy: new Ext.data.HttpProxy({
  19.           url: 'estudiantes2.php',
  20.           method: 'POST',
  21.           id: 'id'
  22.       }),  
  23.       baseParams:{
  24.         task: "showdata",
  25.         start: 0,
  26.         limit: 5,
  27.         idprueba: 1
  28.       },
  29.       reader: reader
  30.   });
  31.   store.load();
  32.   var agregarEstudianteForm = new Ext.form.FormPanel({
  33.     id:'agregarEstudianteForm',
  34.     url: 'agregarEstudiante.php',      
  35.     items: [
  36.       {
  37.         xtype: 'textfield',      // Ext.form.TextField    Componente que acepta datos alfanumericos
  38.         fieldLabel: 'Nombre',
  39.         hiddenName: 'nombre',
  40.         name:'nombre',        
  41.         blankText: 'Nombre completo',
  42.         allowBlank: false
  43.       },
  44.       {
  45.         xtype: 'textfield',      // Ext.form.TextField    Componente que acepta datos alfanumericos
  46.         fieldLabel: 'Edad',
  47.         hiddenName:'edad',
  48.         name:'edad',
  49.         allowBlank: false
  50.       },
  51.       {
  52.         xtype: 'textfield',      // Ext.form.TextField    Componente que acepta datos alfanumericos
  53.         fieldLabel: 'Telefono',
  54.         hiddenName:'telefono',
  55.         name:'telefono'
  56.       }
  57.     ]
  58.    });
  59.  
  60.   var agregarEstudianteWin = new Ext.Window({
  61.     title: 'Nuevo estudiante',
  62.     width: 400,
  63.     height:300,
  64.     modal: true,
  65.     closable:false,
  66.     bodyStyle:'padding:5px;',
  67.     buttonAlign:'center',
  68.     items: agregarEstudianteForm,
  69.     buttons: [
  70.       {
  71.         text: 'Guardar',
  72.         handler: function(){
  73.           if (agregarEstudianteForm.getForm().isValid()) {
  74.             agregarEstudianteForm.getForm().submit({
  75.               method: 'POST',
  76.               waitTitle: 'Validando datos',
  77.               waitMsg: 'Enviando datos..',
  78.               success: function(form, action){
  79.                 var data = Ext.util.JSON.decode(action.response.responseText);
  80.                 alert(data.message.reason);
  81.                 agregarEstudianteForm.getForm().reset();
  82.                 store.reload();
  83.               },
  84.               failure: function(form, action){
  85.                 var data = Ext.util.JSON.decode(action.response.responseText);
  86.                 alert('Error\n' + data.errors.reason);
  87.               }
  88.             });
  89.             agregarEstudianteWin.hide();
  90.           }
  91.         }
  92.       },
  93.       {
  94.         text: 'Cancelar',
  95.         handler: function(){ agregarEstudianteWin.hide(); }
  96.       }
  97.     ]
  98.   });
  99.   function mostrarCurso() {
  100.     var seleccionados = grid.selModel.selections.keys;        
  101.     if(seleccionados.length > 0 ){
  102.       if (confirm('Se cargaran los cursos')){
  103.         var ids = Ext.encode(seleccionados);
  104.         Ext.Ajax.request(
  105.         {  
  106.           waitMsg: 'Cargando ...',
  107.           url: 'cursos2.php',
  108.           params: {
  109.              task: "Show",
  110.              ids: ids,
  111.              key: 'ids'
  112.           },
  113.           callback: function (options, success, response) {
  114.             if (success) {                    
  115.               var json = Ext.util.JSON.decode(response.responseText);
  116.               alert(json.del_count + ' curso(s) cargado(s)');
  117.             } else{
  118.               alert('Error inesperado \n'+ response.responseText);
  119.             }
  120.           },
  121.  
  122.           failure:function(response,options){
  123.              alert('Error ...');
  124.           },
  125.           success:function(response,options){
  126.             store.removeAll();
  127.             store.reload();
  128.           }
  129.         });
  130.       }
  131.     } else {
  132.       alert('Seleccione al menos un registro para mostrar');
  133.     }
  134.   }
  135.   function eliminarEstudiante() {
  136.     var seleccionados = grid.selModel.selections.keys;        
  137.     if(seleccionados.length > 0 ){
  138.       if (confirm('Realmente quiere eliminar los registros selecionados?')){
  139.         var ids = Ext.encode(seleccionados);
  140.         Ext.Ajax.request(
  141.         {  
  142.           waitMsg: 'Eliminando ...',
  143.           url: 'eliminarEstudiante.php',
  144.           params: {
  145.              task: "delete",
  146.              ids: ids,
  147.              key: 'id'
  148.           },
  149.           callback: function (options, success, response) {
  150.             if (success) {                    
  151.               var json = Ext.util.JSON.decode(response.responseText);
  152.               alert(json.del_count + ' registro(s) eliminado(s)');
  153.             } else{
  154.               alert('Error inesperado \n'+ response.responseText);
  155.             }
  156.           },
  157.  
  158.           failure:function(response,options){
  159.              alert('Error ...');
  160.           },
  161.           success:function(response,options){
  162.             store.removeAll();
  163.             store.reload();
  164.           }
  165.         });
  166.       }
  167.     } else {
  168.       alert('Seleccione al menos un registro para eliminar');
  169.     }
  170.   }
  171.   function editarEstudiante(grid) {
  172.     Ext.Ajax.request({
  173.       waitMsg: 'Guardando...',
  174.       url: 'editarEstudiante.php',
  175.       method: 'POST',
  176.       params: {
  177.         task: "update",
  178.         key: 'id',
  179.         keyID: grid.record.data.id,
  180.         data: Ext.encode(grid.record.data),//the column name
  181.         field: grid.field,
  182.         value: grid.value
  183.       },
  184.       failure:function(response,options){
  185.         alert('Error ...');
  186.       },
  187.       success:function(response,options){
  188.         store.reload();
  189.       }
  190.     });
  191.   };
  192.  
  193.   // create the Grid    
  194.   grid = new Ext.grid.EditorGridPanel({
  195.     store: store,
  196.     columns: [
  197.       {
  198.         id       :'nombre',
  199.         header   : 'Nombre',
  200.         dataIndex: 'nombre',
  201.         editor: new Ext.form.TextField({
  202.           allowBlank: false
  203.         })
  204.       },
  205.       {
  206.         header   : 'Edad',
  207.         dataIndex: 'edad',
  208.         editor: new Ext.form.TextField({
  209.           allowBlank: false
  210.         })
  211.       },
  212.       {
  213.         header   : 'Telefono',
  214.         dataIndex: 'telefono',
  215.         editor: new Ext.form.TextField({
  216.           allowBlank: false
  217.         })
  218.       }
  219.     ],
  220.     stripeRows: true,
  221.     autoExpandColumn: 'nombre',
  222.     height: 350,
  223.     width: 300,
  224.     title: 'Estudiantes',
  225.     tbar:[
  226.      {
  227.         text: 'Nuevo',
  228.         tooltip: 'Nuevo estudiante',
  229.         handler: function(){agregarEstudianteWin.show()},
  230.         icon: 'add.png',
  231.         iconAlign: 'top'
  232.      },
  233.      {
  234.         text: 'Eliminar',
  235.         tooltip: 'Eliminar registro',
  236.         handler: eliminarEstudiante,
  237.         icon: 'delete.png',
  238.         iconAlign: 'top'
  239.      },
  240.      {
  241.         text: 'Ver Cursos',
  242.         tooltip: 'Ver Cursos',
  243.         handler: mostrarCurso,
  244.         icon: 'lupa.jpg',
  245.         iconAlign: 'top'
  246.      }
  247.     ],
  248.     bbar: new Ext.PagingToolbar({
  249.        pageSize: 5,
  250.        store: store,
  251.        displayInfo: true
  252.     }),
  253.     listeners:{'afteredit':editarEstudiante},
  254.     selModel: new Ext.grid.RowSelectionModel({singleSelect:true})
  255.   });
  256.  
  257.   // render the grid to the specified div in the page
  258.   grid.render('gridn');
  259.  
  260. });

El otro js es parecido solo que me muesta los cursos.

Y asi los visualizo
Código HTML:
Ver original
  1.     <title>Ejemplo GRID</title>
  2.     <link rel="stylesheet"
  3.          type="text/css"
  4.          href="ext34/resources/css/ext-all.css" />
  5.  
  6.     <script src="ext34/adapter/ext/ext-base.js"></script>
  7.     <script src="ext34/ext-all.js"></script>
  8.     <script src="cursos2.js"></script>
  9.     <script src="estudiantes2.js"></script>
  10.     <style>
  11.     .izquierda {
  12.     float:left;
  13.     }
  14.     .derecha {
  15.     float:left;
  16.     width:320px;
  17.     }
  18. </style>
  19. </head>
  20.    <div id="gridn" class="derecha"></div>
  21.     <div id="gridc" class="derecha"></div>
  22. </body>
  23. </html>

Espero que me puedan orientar un poco.

Saludos.
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #2 (permalink)  
Antiguo 08/12/2013, 21:39
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: Recargar 2 Grid con extjs

Me habia olvidado de este post, por si alguien busca algo parecido puede revisar el libro.

ext js cookbook.
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.

Etiquetas: ajax, campos, extjs, grid, js, php
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 02:20.