php - Updating database with Ext Store Writer - ExtJS 4.2 -
i had modified sencha's writers example, couldn't make update data in database. have php script @ server's side, can not see update call extjs. using reader data, , works fine, when try update data sending server, never call.
here code:
ext.require([ 'ext.grid.*', 'ext.data.*', 'ext.util.*', 'ext.state.*', 'ext.form.*' ]); ext.onready(function(){ // define our data model ext.define('empresa', { extend: 'ext.data.model', fields: [ { name: 'id', type: 'int' }, { name: 'nombre', type: 'string' }, { name: 'estado', type: 'int' }, { dateformat: 'd/m/y', name: 'fechacreacion', type: 'string' } ] }); // create data store var store = ext.create('ext.data.store', { // destroy store if grid destroyed autodestroy: true, model: 'empresa', //autoload: true, proxy: { type: 'jsonp', api: { read: 'http://fplweb2.localhost/empresa/listar/', write: 'http://fplweb2.localhost/empresa/grabar/', update: 'http://fplweb2.localhost/empresa/grabar/', destroy: 'http://fplweb2.localhost/empresa/eliminar/', }, reader: { type: 'json', root: 'listaempresas' }, writer: { type: 'json' } }, sorters: [{ property: 'start', direction: 'asc' }] }); store.load(); var rowediting = ext.create('ext.grid.plugin.rowediting', { clickstomoveeditor: 1, autocancel: false }); // create grid , specify field want // use editor @ each column. var grid = ext.create('ext.grid.panel', { store: store, columns: [ { xtype: 'gridcolumn', dataindex: 'id', text: 'id', editor: 'numberfield' }, { xtype: 'gridcolumn', dataindex: 'nombre', text: 'nombre', editor: 'textfield' }, { xtype: 'gridcolumn', dataindex: 'estado', text: 'estado', editor: 'numberfield' }, { xtype: 'gridcolumn', dataindex: 'fechacreacion', text: 'fechacreacion', editor: 'datefield' } ], renderto: ext.getbody(), height: 600, title: 'lista de empresas', tbar: [{ text: 'agregar empresa', handler : function() { rowediting.canceledit(); // create model instance var r = ext.create('empresa', { id: store.getcount() + 1, nombre: 'nueva empresa', estado: '1', fechacreacion: ext.date.cleartime(new date()) }); store.insert(0, r); rowediting.startedit(0, 0); console.log('antes de' + store.getcount()); //store.sync(); console.log('despues de: ' + store.getcount()); } }, { itemid: 'removeempresa', text: 'eliminar empresa', handler: function() { var sm = grid.getselectionmodel(); rowediting.canceledit(); store.remove(sm.getselection()); if (store.getcount() > 0) { sm.select(0); } }, disabled: true }], plugins: [rowediting], listeners: { 'selectionchange': function(view, records) { grid.down('#removeempresa').setdisabled(!records.length); } } }); });
and servers side script returns reader:
{"listaempresas":[{"id":"1","nombre":"dys nevados srl","estado":"1","fechacreacion":"2013-05-13 10:40:00"}]}
i had read in post need store.sync()
error. using extj 4.2
. looking in documentation, method doesn't exists. i'm doing wrong?
enable autosync
of store:
var store = ext.create('ext.data.store', { autosync : true // ... }
the default value false
. store automatically sync after every edit.
Comments
Post a Comment