-
Ext.foro.Novato
Mensajes: 94 Registrado: 01 Dic 2010, 14:11 Ubicación: Villaflores,Chiapas,Mexico.
|
 Publicado: 15 Abr 2011, 19:01
Ultima actualizacion de Codigo: Este nos permite hacer un Update a los datos en Msql y ademas nos elimina el registro en blanco que se produce despues de insertar y luago dar click en cancelar: Js: - Código: Seleccionar todo
/*** LIA Hiber Tadeo Moreno Tovilla (IcebergDelphi) INITEC Software... Abril 2011*/ Ext.onReady(function(){ Ext.QuickTips.init(); var Sm= new Ext.grid.RowSelectionModel({singleSelect: true});//Declaramos el Row Seleccionador del Grid var Status=0; // 1 Se esta Insertando // Registros que se Crearan en blanco, si no los creamos no se insertara ninguna fila var Datos = Ext.data.Record.create([ {name: 'titel', type: 'string'}, {name: 'interpret', type: 'string'}, {name: 'jahr',type: 'string'} ]); //creamos el Store para la Grilla var storeCD = new Ext.data.Store({ url: '/CursosExjs/crudroweditor/php/TCd.php', reader:new Ext.data.JsonReader ({ root: 'data', fields: [ { name:'Titulo' }, { name:'Interprete' }, { name:'Anio' }, { name:'Id' }, ] }) }); var editor = new Ext.ux.grid.RowEditor({ saveText: 'Guardar', cancelText:'Cancelar', clicksToEdit: 2, listeners: { afteredit: function(roweditor, changes, record, rowIndex) { if (Status==0) { var UpdateRec=MyGrd.getSelectionModel().getSelected().get('Id'); Ext.Ajax.request({ url:'/CursosExjs/crudroweditor/php/IEDCd.php?Opcion=Editar', method:'POST', params: { Titulo:record.get('Titulo'), Interprete:record.get('Interprete'), Anio:record.get('Anio'), Id:UpdateRec, }, }); } else { Ext.Ajax.request({ url:'/CursosExjs/crudroweditor/php/IEDCd.php?Opcion=Agregar', method:'POST', params: { Titulo:record.get('Titulo'), Interprete:record.get('Interprete'), Anio:record.get('Anio'), }, }); } }, canceledit:function(rowEditor){ var record = MyGrd.store.getAt(rowEditor.rowIndex); if(Status==1) { MyGrd.store.removeAt(rowEditor.rowIndex); MyGrd.getView().refresh(); Status=0; } return true; } }, }); var MyGrd = new Ext.grid.GridPanel({ store: storeCD, width: 600, region:'center', margins: '0 5 5 5', height: 400, selModel:Sm, renderTo: document.body, plugins: [editor], columns: [ { header : 'Id', dataIndex: 'Id', hidden:true, editor : new Ext.form.TextField() }, { header : 'Titulo', dataIndex: 'Titulo', width: 200, editor : new Ext.form.TextField() }, { header : 'Interprete', dataIndex: 'Interprete', width: 200, editor : new Ext.form.TextField() }, { header : 'Anio', dataIndex: 'Anio', editor : new Ext.form.TextField() } ], tbar: [{ text: 'Agregar CD', iconCls: 'add', handler: onAdd }, '-', { text: 'Eliminar', iconCls: 'delete', handler: onDelete }, ] }); // Carga del Store storeCD.load(); /*** Funcion Agregar */ function onAdd(btn, ev) { var MyData = new Datos({ //Estos registros se crearon anteriomente en la linea 5 titel : '', interpret: '', jahr : '' }); editor.stopEditing(); MyGrd.store.insert(0, MyData); MyGrd.getSelectionModel().selectRow(0); editor.startEditing(0); Status=1; } /** Funcion Eliminar Registro, aqui habria que poner un AjaxRequest para eliminar, etc.*/ function onDelete() { var DeleteRec=MyGrd.getSelectionModel().getSelected().get('Id'); var rec = MyGrd.getSelectionModel().getSelected(); if (!rec) { return false; } alert('Eliminando mediante AjaxRequest el Registro:'+DeleteRec); MyGrd.store.remove(rec); }
});
/*editor.on({ scope: this, afteredit: function(roweditor, changes, record, rowIndex) { //your save logic here - might look something like this: afteredit: function(roweditor, changes, record, rowIndex) { Ext.Ajax.request({ url:'/CursosExjs/crudroweditor/php/IEDCd.php?Opcion=Agregar', method:'POST', params: { Titulo:record.get('titel'), Interprete:record.get('interpret'), Anio:record.get('jahr'), }, success: function() { } }) } } });*/
PHP: - Código: Seleccionar todo
<?php // Conexion a la Bd require '../php/database.php'; $Opcion = $_REQUEST["Opcion"];
switch ($Opcion) { Case 'Agregar': //SQL Insercion // Variables para insercion de valores $Titulo = $_POST['Titulo']; $Interprete = $_POST['Interprete']; $Anio = $_POST['Anio']; $Id=$_POST['Id']; $sqlinsert ="INSERT INTO `cds` (`titel`,`interpret`,`jahr`) VALUES ('$Titulo', '$Interprete', '$Anio');"; $result = mysql_query($sqlinsert,$connection);
// Generando respuestas desde PHP para ExtJs if(!$result) { echo "{ 'success': false, 'msg': 'Ocurrio Un Error intente porfavor mas tarde.' }"; } else { echo "{ 'success': true, 'msg': 'Datos Grabados en Forma Exitosa.' }"; } break; Case 'Editar': // Variables para insercion de valores $Titulo = $_POST['Titulo']; $Interprete = $_POST['Interprete']; $Anio = $_POST['Anio']; $Id=$_POST['Id']; //SQL Update $SqlUpdate ="UPDATE `cds` SET `titel`='$Titulo', `interpret`='$Interprete', `jahr`='$Anio' WHERE `id`='$Id' LIMIT 1;"; $result = mysql_query($SqlUpdate,$connection);
// Generando respuestas desde PHP para ExtJs if(!$result) { echo "{ 'success': false, 'msg': 'Ocurrio Un Error en la Aactualizacion intente porfavor mas tarde.' }"; } else { echo "{ 'success': true, 'msg': 'Datos Actualizados en Forma Exitosa.' }"; } break; }
// Cerramos la Bd mysql_close($connection); ?>
Icebergdelphi Villaflores,Chiapas,Mexico.
|