/*!
* Ext JS Library 4.0
* Copyright(c) 2006-2011 Sencha Inc.
*
[email protected]
* http://www.sencha.com/license
*/
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'price', type: 'float'}
]
});
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url: 'php/newgrid.php',
reader: {
type: 'json',
root: 'users'
},
extraParams: {
mytype: 'list'
},
actionMethods: {
create: 'POST', read: 'POST', update: 'POST', destroy: 'POST'
}
},
autoLoad: true
});
var myCheckbox = Ext.create('Ext.selection.CheckboxModel', {
listeners: {
selectionchange: function(sm, selections) {
//Ext.getCmp('grid-win') -- อ้างอิง id
Ext.getCmp('grid-newGrid').down('#removeButton').setDisabled(selections.length === 0);
}
}
});
Ext.define('MyDesktop.NewGrid', {
extend: 'Ext.ux.desktop.Module',
requires: [
'Ext.data.ArrayStore',
'Ext.util.Format',
'Ext.grid.Panel',
'Ext.grid.RowNumberer',
'Ext.selection.CheckboxModel'
],
id:'grid-newGrid',
init : function(){
this.launcher = {
text: 'New Grid TEST',
iconCls:'icon-grid'
};
},
createWindow : function(){
var desktop = this.app.getDesktop();
var win = desktop.getWindow('grid-newGrid');
if(!win){
win = desktop.createWindow({
id: 'grid-newGrid',
title:'TESTING GRID WINDOW',
width:740,
height:480,
iconCls: 'icon-grid',
animCollapse:false,
constrainHeader:true,
layout: 'fit',
items: [
{
border: false,
xtype: 'grid',
store: myStore,
selModel: myCheckbox,
columns: [
new Ext.grid.RowNumberer(),
{
text: "Company",
flex: 1,
sortable: true,
dataIndex: 'name'
},
{
text: "Price",
width: 70,
sortable: true,
renderer: Ext.util.Format.usMoney,
dataIndex: 'price'
}
]
}
],
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
ui: 'footer',
layout: {
pack: 'center'
},
items: [{
minWidth: 80,
text: 'Save'
},{
minWidth: 80,
text: 'Cancel'
}]
}, {
xtype: 'toolbar',
items: [{
text:'Add Something',
tooltip:'Add a new row',
iconCls:'add'
}, '-', {
text:'Options',
tooltip:'Set options',
iconCls:'option'
},'-',{
itemId: 'removeButton',
text:'Remove Something',
tooltip:'Remove the selected item',
iconCls:'remove',
disabled: true,
handler: function(){
var TEST = Ext.getCmp('grid-newGrid').getView().getSelectionModel().getSelection();
console.log(TEST);
}
}]
}]
});
}
return win;
}
});