2012-11-02 40 views
0

嗨,大家好,我正在使用直接网格的小数据更新部分示例问题是我无法使用单元插件更新数据,我可以添加和删除,它有直接更新到分贝,但是当我编辑现有的领域,它不显示任何错误和屏幕上的更新,我没有看到任何邮政响应网络区域或控制台的铬我不为什么它没有发生如何使用extjs4网格更新选项更新Mysql上的数据

这里的代码,请帮助

Ext.onReady(function() { 
    Ext.direct.Manager.addProvider(Ext.app.REMOTING_API); 

    //added model inside onready 
    Ext.define('PersonalInfo', { 
     extend: 'Ext.data.Model', 
     fields: ['id', 'name', 'address', 'state','st_one','st_two','st_three','st_for'] 
    }); 

    //separated store into unique var for guaranteeRange 
    var store = Ext.create('Ext.data.Store', { 
     id: 'store', 
     model: 'PersonalInfo', 
     autoLoad: true, 
     proxy: { 
      type: 'direct', 
      api: { 
       create:QueryDatabase.createRecord, 
       read:QueryDatabase.getResults, 
       update:QueryDatabase.updateRecords, 
       destroy:QueryDatabase.destroyRecord 
      } 
     } 
    }); 

    var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { 
     clicksToMoveEditor: 1, 
     autoCancel: false 

    }); 


    var alphaSpaceTest = /^[-\sa-zA-Z]+$/; 

    Ext.apply(Ext.form.field.VTypes, { 
     // vtype validation function 
     alphaSpace: function(val, field) { 
      return alphaSpaceTest.test(val); 
     }, 
     // vtype Text property: The error text to display when the validation function returns false 
     alphaSpaceText: 'Not a valid state. Must not contain numbers.', 
     // vtype Mask property: The keystroke filter mask 
     alphaSpaceMask: /^[-\sa-zA-Z]+$/ 
    }); 

    // create the Grid 
    var grid = Ext.create('Ext.grid.Panel', { 
     //height: 550, 
     //width: 800, 
     cls: 'grid', 
     title: 'Production Planning Control', 
     store: store, 
     columns: [{ 
      dataIndex: 'id', 
      width: 50, 
      text: 'ID' 
     }, { 
      dataIndex: 'name', 
      flex: 0.5, 
      text: 'ClientName', 
      //pt 2 
      allowBlank: false, 
      field: { 
       type: 'textfield', 
       allowBlank: false 
      } 
     }, { 
      dataIndex: 'address', 
      flex: 0.5, 
      text: 'Product Name', 
      //pt 2 
      allowBlank: false, 
      field: { 
       type: 'textfield', 
       allowBlank: false 
      } 
     }, { 
      dataIndex: 'state', 
      flex: 0.8, 
      text: 'No Of QtyRequired', 
      //pt 2 
      allowBlank: false, 
      field: { 
       type: 'textfield', 
       allowBlank: false, 
       //vtype: 'alphaSpace' 
      } 
     },{ 
      dataIndex: 'st_one', 
      flex: 0.7, 
      text: 'Station 1', 
      //pt 2 
      allowBlank: false, 
      field: { 
       type: 'textfield', 
       //allowBlank: false, 
       //vtype: 'alphaSpace' 
      } 
}, 
      { 
      dataIndex: 'st_two', 
      flex: 0.7, 
      text: 'Station 2', 
      //pt 2 
      allowBlank: false, 
      field: { 
       type: 'textfield', 
       //allowBlank: false, 
       //vtype: 'alphaSpace' 
      } 
     },{ 
      dataIndex: 'st_three', 
      flex: 0.7, 
      text: 'Station 3', 
      //pt 2 
      allowBlank: false, 
      field: { 
       type: 'textfield', 
       //allowBlank: false, 
       //vtype: 'alphaSpace' 
      } 
     }, 
      { 
      dataIndex: 'st_for', 
      flex: 0.7, 
      text: 'Station 4', 
      //pt 2 
      allowBlank: false, 
      field: { 
       type: 'textfield', 
       //allowBlank: false, 
       //vtype: 'alphaSpace' 
      } 
     } 

     ], 
     renderTo: Ext.getBody(), 
     //pt 2 
     plugins: [ 
      rowEditing 
     ], 
     dockedItems: [{ 
      xtype: 'toolbar', 
      store: store, 
      dock: 'bottom', 
      //creating, add items 
      items: [{ 
       iconCls: 'add', 
       text: 'Add', 
       handler: function() { 
        rowEditing.cancelEdit(); 
        // create a record 
        var newRecord = Ext.create('PersonalInfo'); 
        store.insert(0, newRecord); 
        rowEditing.startEdit(0, 0); 

        // write about this section in tutorial 
        var sm = grid.getSelectionModel(); 
        grid.on('edit', function() { 

         var record = sm.getSelection(); 
         store.record.commit(); 
         //store.sync(); 
         //e.record.commit(); 
         //store.commitChanges(); 
         store.remove(record); 
         store.load(); 
         store.sync(); 
         alert ('dome'); 




        }); 
       } 
      }, { 
       iconCls: 'delete', 
       text: 'Delete', 
       handler: function() { 
        rowEditing.cancelEdit(); 
        var sm = grid.getSelectionModel(); 
        Ext.Msg.show({ 
         title:'Delete Record?', 
         msg: 'You are deleting a record permanently, this cannot be undone. Proceed?', 
         buttons: Ext.Msg.YESNO, 
         icon: Ext.Msg.QUESTION, 
         fn: function(btn){ 
          if(btn === 'yes') { 
           store.remove(sm.getSelection()); 
           store.sync(); 
          } 
         } 
        }); 
       } 
      }, 
      { 
       xtype: 'button', 
       iconCls:'refresh', 
       text: 'Refresh Grid', 
      // action: 'refresh', 
       handler:function(){ 
        //var reload=this.getGridPanel().getStore(); 
        store.load(); 
       } 

      }] 
     }] 
    }); 
}); 

回答

0

你可以使用autoSync:true存储配置,系统将自动发布。

+0

但是我们在哪里都使用它像这里@dbrin 'code'var rowEditing = Ext.create( 'Ext.grid.plugin.RowEditing',{ \t \t clicksToMoveEditor:1, \t \t autoCancel:假, \t \t autoSync:true \t}); –

+0

autoSync是商店属性。 – dbrin

+0

让我在商店里做! –