v221919
12 Apr 2012, 4:25 AM
Below is my code I want to add the data in textfield to the store and bind it to the grid.
This should happen when i click on button..
Ext.create('Ext.data.Store', {
storeId:'dataStore',
fields:['name', 'lastname', 'dob', 'email', 'Mobile'],
data:[
{name:"Michael", lastname:"Scott",dob:"4/12/2012"},
{name:"Dwight", lastname:"Schrute"},
{name:"Jim", lastname:"Halpert"}
]
});
Ext.application({
name: 'app',
launch: function () {
Ext.define('MyApp.view.ui.MyWindow', {
extend: 'Ext.window.Window',
height: 505,
width: 462,
title: 'My Window',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'form',
height: 270,
padding: 5,
bodyPadding: 10,
title: 'My Form',
items: [
{
xtype: 'textfield',
id: 'txtnm',
fieldLabel: 'Name',
allowBlank: false,
anchor: '100%'
},
{
xtype: 'textareafield',
id: 'txtadd',
fieldLabel: 'Address',
allowBlank: false,
anchor: '100%'
},
{
xtype: 'datefield',
id: 'dtDob',
fieldLabel: 'DOB',
allowBlank: false,
anchor: '100%'
},
{
xtype: 'textfield',
id: 'txtemail',
fieldLabel: 'Email',
allowBlank: false,
vtype: 'email',
anchor: '100%'
},
{
xtype: 'textfield',
id: 'txtmob',
fieldLabel: 'Mobile no',
allowBlank: false,
maskRe: /[0-9]/,
maxLength: 10,
minLength: 10,
anchor: '100%'
},
{
xtype: 'textfield',
id: 'txtpwd',
inputType: 'password',
fieldLabel: 'Password',
allowBlank: false,
anchor: '100%'
}
]
},
{
xtype: 'button',
id: 'btnSubmit',
margin: '0 0 5 200',
text: 'Submit',
listeners:
{
click : function()
{
alert("hi");
dataStore.add( new record
({
name:"abcd"
}) );
}
}
},
{
xtype: 'gridpanel',
height: 174,
padding: 5,
width: 450,
title: 'My Grid Panel',
store: Ext.data.StoreManager.lookup('dataStore'),
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'String'
},
{
xtype: 'gridcolumn',
dataIndex: 'lastname',
text: 'String'
},
// {
// xtype: 'numbercolumn',
// dataIndex: 'number',
// text: 'Number'
// },
{
xtype: 'datecolumn',
dataIndex: 'dob',
text: 'Date'
}
],
viewConfig: {
}
}
]
});
me.callParent(arguments);
}
});
var win = Ext.create('MyApp.view.ui.MyWindow');
win.show();
}
});
This should happen when i click on button..
Ext.create('Ext.data.Store', {
storeId:'dataStore',
fields:['name', 'lastname', 'dob', 'email', 'Mobile'],
data:[
{name:"Michael", lastname:"Scott",dob:"4/12/2012"},
{name:"Dwight", lastname:"Schrute"},
{name:"Jim", lastname:"Halpert"}
]
});
Ext.application({
name: 'app',
launch: function () {
Ext.define('MyApp.view.ui.MyWindow', {
extend: 'Ext.window.Window',
height: 505,
width: 462,
title: 'My Window',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'form',
height: 270,
padding: 5,
bodyPadding: 10,
title: 'My Form',
items: [
{
xtype: 'textfield',
id: 'txtnm',
fieldLabel: 'Name',
allowBlank: false,
anchor: '100%'
},
{
xtype: 'textareafield',
id: 'txtadd',
fieldLabel: 'Address',
allowBlank: false,
anchor: '100%'
},
{
xtype: 'datefield',
id: 'dtDob',
fieldLabel: 'DOB',
allowBlank: false,
anchor: '100%'
},
{
xtype: 'textfield',
id: 'txtemail',
fieldLabel: 'Email',
allowBlank: false,
vtype: 'email',
anchor: '100%'
},
{
xtype: 'textfield',
id: 'txtmob',
fieldLabel: 'Mobile no',
allowBlank: false,
maskRe: /[0-9]/,
maxLength: 10,
minLength: 10,
anchor: '100%'
},
{
xtype: 'textfield',
id: 'txtpwd',
inputType: 'password',
fieldLabel: 'Password',
allowBlank: false,
anchor: '100%'
}
]
},
{
xtype: 'button',
id: 'btnSubmit',
margin: '0 0 5 200',
text: 'Submit',
listeners:
{
click : function()
{
alert("hi");
dataStore.add( new record
({
name:"abcd"
}) );
}
}
},
{
xtype: 'gridpanel',
height: 174,
padding: 5,
width: 450,
title: 'My Grid Panel',
store: Ext.data.StoreManager.lookup('dataStore'),
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'String'
},
{
xtype: 'gridcolumn',
dataIndex: 'lastname',
text: 'String'
},
// {
// xtype: 'numbercolumn',
// dataIndex: 'number',
// text: 'Number'
// },
{
xtype: 'datecolumn',
dataIndex: 'dob',
text: 'Date'
}
],
viewConfig: {
}
}
]
});
me.callParent(arguments);
}
});
var win = Ext.create('MyApp.view.ui.MyWindow');
win.show();
}
});