Code:
Ext.require([
'Ext.form.*',
'Ext.layout.container.Column',
'Ext.tab.Panel',
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.state.*'
]);
Ext.define('Writer.Person', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'float'},
{name: 'name', type: 'string'},
{name: 'price', type: 'float'}
]
});
var store = Ext.create('Ext.data.Store', {
model: 'Writer.Person',
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
api: {
read: 'php/newgrid.php?mytype=list',
create: 'php/newgrid.php?mytype=add',
update: 'php/newgrid.php?mytype=edit',
destroy: 'php/newgrid.php?mytype=remove'
},
reader: {
type: 'json',
successProperty: 'success',
root: 'users',
messageProperty: 'message'
},
writer: {
type: 'json',
writeAllFields: false,
root: 'users'
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
},
listeners: {
write: function(proxy, operation){
if (operation.action == 'destroy') {
//main.child('#form').setActiveRecord(null);
}
Ext.Msg.alert(operation.action, 'ดำเนินการเสร็จสิ้น',onSync());
jsonData: Ext.util.JSON.encode(dataObj);
}
},
});
var onAddClick = function() {
store.add({
name: Ext.getCmp('formname').getValue(),
price: Ext.getCmp('formprice').getValue()
});
myform.hide();
};
var onDeleteClick = function() {
var sm = grid.getSelectionModel();
store.remove(sm.getSelection());
};
var createColumns = function (finish, start) {
var columns = [
new Ext.grid.RowNumberer(),
{header: 'name',dataIndex: 'name',flex: 1},
{header: 'price',dataIndex: 'price',flex: 1}
];
return columns.slice(start || 0, finish);
};
var onSync = function(){
store.reload();
};
var onOpenForm = function(){
myform.show();
};
var myform = new Ext.Window({
id : 'xform-win-addAddress',
title:'Add item',
layout : 'fit',
autoShow : false,
closeAction: 'hide',
width : 300,
height : 150,
items : [{
xtype : 'form',
bodyPadding : 5,
flex : 1,
defaultType : 'textfield',
items : [{
name : 'name',
fieldLabel : 'Name',
id : 'formname',
allowBlank:false
}, {
name : 'price',
fieldLabel : 'Price',
id : 'formprice',
xtype: 'numberfield',
allowBlank:false
}]
}],
buttons : [{
text : 'save',
iconCls : 'add',
handler: this.onAddClick
}, {
text : 'Cancel',
iconCls : 'remove',
handler: function(){
myform.hide();
}
}]
});
var grid = Ext.create('Ext.grid.Panel', {
store: store,
columns: createColumns(3),
dockedItems: [{
xtype: 'toolbar',
items: [{
iconCls: 'add',
text: 'เพิ่มข้อมูล',
scope: this,
handler: this.onOpenForm
}, {
iconCls: 'remove',
text: 'ลบข้อมูล',
disabled: true,
itemId: 'delete',
scope: this,
handler: this.onDeleteClick
}]
}],
listeners: {
'selectionchange': function(view, records) {
grid.down('#delete').setDisabled(!records.length);
}
}
});
Ext.define('MyDesktop.test', {
extend: 'Ext.ux.desktop.Module',
id:'grid-test',
init : function(){
this.launcher = {
text: 'TEST GRID 2',
iconCls:'icon-grid'
};
},
createWindow : function(){
var desktop = this.app.getDesktop();
var win = desktop.getWindow('grid-test');
if(!win){
win = desktop.createWindow({
//--
id: 'grid-test',
title:'TESTING GRID WINDOW',
width: 500,
height: 300,
iconCls: 'icon-grid',
animCollapse:false,
constrainHeader:true,
items: grid
//--
});
}
return win;
}
});
Aucun commentaire:
Enregistrer un commentaire