-
Ext.foro.Moderador
Mensajes: 353 Registrado: 17 Ago 2009, 12:06
|
 Publicado: 25 Ene 2012, 18:15
Desconozco como trabajas tu codigo pero te voy a colocar codigo de ejemplo que podrias usar: - Código: Seleccionar todo
Ext.onReady(function() { var form = new Ext.form.FormPanel({ id: 'form', url:'peliculas.php', padding: 10, defaults:{ allowBlank: false }, items:[ { xtype: 'hidden', id: 'id' },{ xtype: 'numberfield', id: 'anio', fieldLabel: 'Año', anchor: '50%' }, { xtype: 'textfield', id: 'director', fieldLabel: 'Director', anchor: '100%' }, { xtype: 'textarea', id: 'sinopsis', fieldLabel: 'sinopsis', anchor: '100%', allowBlank: true } ] }); var winform = new Ext.Window({ id: 'winform', height: 200, closeAction:'hide', resizable: false, width: 400, layout: 'fit', modal: true, items:[form], fbar: [ { xtype: 'button', text: 'guardar', handler: function(){ form.getForm().submit({ params: { operacion: 'editar' }, success: function(form, action){ Ext.StoreMgr.lookup('store_detalles').reload(); winform.hide(); } }); } } ], listeners: { hide: function(){ var form = Ext.getCmp('form'); form.getForm().reset(); }, show : function(){ Ext.Ajax.request({ url: 'peliculas.php', params: { operacion: 'buscar_detalle', id: this.id }, scope: this, success: function(response){ info = Ext.decode(response.responseText); console.debug(info); Ext.getCmp('form').getForm().loadRecord(info); }, failure: function(response){ } }); } } }); var store_peliculas = new Ext.data.JsonStore({ storeId: 'store_peliculas', url: 'peliculas.php', baseParams:{ operacion: 'consultar' }, root: 'data', totalProperty: 'total', fields: ['id','titulo'] }); var store_detalles = new Ext.data.JsonStore({ storeId: 'store_detalles', url: 'peliculas.php', baseParams:{ operacion: 'consultar_detalle' }, root: 'data', fields: ['id','director','anio','sinopsis'] }); store_peliculas.load({params:{start:0,limit:10}}); var pager = new Ext.PagingToolbar({ store: store_peliculas, displayInfo: true, displayMsg: '{0} - {1} of {2} Peliculas', emptyMsg: 'No hay peliculas que mostrar', pageSize: 10 }); var grilla_peliculas = new Ext.grid.GridPanel({ flex: 1, id: 'grilla_peliculas', store: store_peliculas, viewConfig:{ forceFit: true }, columns: [ new Ext.grid.RowNumberer(), {header:'Titulo', dataIndex:'titulo',sortable: true} ], tbar: [ { xtype: 'button', text: 'Editar información', handler: function(){ var grilla = Ext.getCmp('grilla_peliculas'); var registro = grilla.getSelectionModel().getSelected(); if (!Ext.isDefined(registro)){ Ext.Msg.show({ title: 'ERROR', msg: 'Seleccione una pelicula primero', icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK }); return; } winform.id = registro.get('id'); winform.show(); } } ], bbar: pager, stripeRows: true, listeners :{ rowclick : function(grid, index, record){ Ext.StoreMgr.lookup('store_detalles').load({ params:{ id: grid.getStore().getAt(index).get('id') } }); } } }); var grilla_detalles = new Ext.grid.GridPanel({ flex: 1, id: 'grilla_detalles', store: store_detalles, columns: [ {header:'Director', dataIndex:'director',sortable: true}, {header:'Año', dataIndex:'anio',sortable: true}, {header:'Sinopsis', dataIndex:'sinopsis'}, ], stripeRows: true }); var win = new Ext.Window({ width : 800, height : 500, title : 'Peliculas', layout: 'hbox', layoutConfig: { align: 'stretch' }, items:[ grilla_peliculas, grilla_detalles ] }); win.show(); });
y en le lado del PHP (imagino usas php) - Código: Seleccionar todo
<?php mysql_connect("localhost","root","root") or die ("No se pudo conectar con el servidor"); mysql_select_db("test") or die; $operacion = $_POST['operacion']; switch ($operacion){ case 'consultar': consultar_peliculas(); break; case 'consultar_detalle': consultar_detalle(); break; case 'buscar_detalle': buscar_detalle(); break; case 'editar': editar_detalle(); break; } function consultar_peliculas(){ $sql = "SELECT * FROM peliculas"; $arr = array(); $rs = mysql_query($sql) or die(mysql_error()); while($obj = mysql_fetch_object($rs)){ $arr[] = $obj; } echo '{"success": true, "data": '.json_encode($arr).'}'; } function consultar_detalle(){ $id = $_POST['id']; $sql = "SELECT * FROM peliculas WHERE id = $id"; $arr = array(); $rs = mysql_query($sql) or die(mysql_error()); while($obj = mysql_fetch_object($rs)){ $arr[] = $obj; } echo '{"success": true, "data": '.json_encode($arr).'}'; } function buscar_detalle(){ $id = $_POST['id']; $sql = "SELECT * FROM peliculas WHERE id = $id"; $arr = array(); $rs = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($rs) > 0) { while($obj = mysql_fetch_object($rs)){ $arr[] = $obj; } $json = json_encode($arr); $json = str_replace("[","",$json); $json = str_replace("]","",$json); echo '{"success":true,"data":'.$json.'}'; } } function editar_detalle(){ $id = $_POST['id']; $anio = $_POST['anio']; $director = $_POST['director']; $sinopsis = $_POST['sinopsis']; $sql = "UPDATE peliculas SET anio = '$anio', director = '$director', sinopsis = '$sinopsis' WHERE id = $id"; $rs = mysql_query($sql) or die(mysql_error()); } ?>
espero te sirva (^_^) pd: trata de no usar la palabra "Urgente!!" en los titulos de tus post como te lo sugiere el post de Ramiro P. Saenz en http://www.extjses.com/anuncios/leer-como-debo-exponer-pregunta-t339.html# Utiliza un título descriptivo de tu problema para tu mensaje. Títulos como "Urgente!!!", "Ayuda por favor!!!" o "Solo expertos!" no ayudarán mucho a que nadie se anime a entrar a leer tu problema.
|