I need help in Sencha Calculator working Real Time - sencha-touch

am trying to build a calculator that binds data in real time without the user pressing the calculate button. so far i can get my application to work but the user has to hit on the calculate button to perform the calculation which is not what i want.
My problem now is how can i make my calculator to work on real time meaning that once the first, second and third text-fields are filled, the fourth text-field will auto generate the answer without the calculation button being pressed. 1 + 1 + 1 = (3) the 3 will be auto generated in real time once the first 3 text-fields are filled. below are my codes so far:
Ext.define("ikhlas.view.login", {
extend: 'Ext.Panel',
xtype: 'loginpanel',
config:{
title: 'Login',
iconCls: 'more',
styleHtmlContent: true,
layout:{
type: 'vbox',
},
items: [
{
xtype: 'container',
iconCls: 'add',
items: [
{
xtype: 'textfield',
name: 'email',
id: 'txtField1',
placeHolder: 'Sum 1'
},
{
xtype: 'spacer',
height: 10,
},
{
xtype: 'textfield',
name: 'password',
id: 'txtField2',
placeHolder: 'Sum 2'
},
{
xtype: 'spacer',
height: 10,
},
{
xtype: 'textfield',
name: 'password',
id: 'txtField3',
placeHolder: 'Sum 3'
},
{
xtype: 'spacer',
height: 10,
},
{
xtype: 'textfield',
id: 'txtField4',
name: 'password',
placeHolder: 'Sum 4'
},
]},
{
xtype: 'button',
text: 'Calculate',
ui: 'confirm',
width: '30%',
height: '6%',
flex: 1,
left: '55%',
top: '65%',
action: 'submitBtn'
},
]}
});
And my Controller looks like this:
Ext.define('ikhlas.controller.SubmitController',{
extend: 'Ext.app.Controller',
config:{
refs:{
submitBtn: '#submitBtn',
txtField1: '#txtField1',
txtField2: '#txtField2',
txtField3: '#txtField3',
txtField4: '#txtField4'
},
control:{
'button[action=submitBtn]':{
tap :'submitbutton'
}
}
},
submitbutton:function(){
var value1 = Ext.getCmp('txtField1').getValue();
var value2 = Ext.getCmp('txtField2').getValue();
var value3 = Ext.getCmp('txtField3').getValue();
var value4;
value4 = value1 * value2 * value3;
Ext.getCmp('txtField4').setValue(value4);
}
});
So far the app is working fine with the code giving, but i need a real time calculation that's my objective. Hope someone can help out.
My store and My model are all empty for now.

I havenĀ“t tried it myself, but I think you have to listen to the changeevent of your textfields and whenever a value changes, you have to recalculate the value.
So for every of your input textfields, add this to your controller:
control: {
'button[action=submitBtn]': {
tap: 'submitbutton'
},
// this should call your submitbutton function which calculates the values
// every time the value of textfield1 changes
txtField1: {
change: 'submitbutton',
}
}

A Simple caculator
Ext.define('Calc.view.Main', {
extend: 'Ext.form.Panel',
fullscreen:true,
config: {
items: [
{
layout:'vbox',
style:'background-color:blue',
flex:1,
items:[
{
xtype:'textareafield',
name:'display',
style:'border:5px inset blue',
id:'display',
value:"0"
}
]
},
{
layout:'hbox',
style:'background-color:#cccccc',
flex:1,
items :[
{
xtype:'button',
text:'1',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("1");
}
else
{
num=num+"1";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
},
{
xtype:'button',
text:'2',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print 2");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("2");
}
else
{
num=num+"2";
Ext.getCmp('display').setValue(num);
}
console.log(num);
/*Ext.getCmp('display').setValue("2");
var num=Ext.getCmp('display').getValue();
num=num*10+1;
Ext.getCmp('display').setValue(num);
console.log(num);*/
}
},
{
xtype:'button',
text:'3',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 3");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("3");
}
else
{
num=num+"3";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
}
]
},
{
layout:'hbox',
style:'background-color:#909090',
flex:1,
items:[
{
xtype:'button',
text:'4',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 4");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("4");
}
else
{
num=num+"4";
Ext.getCmp('display').setValue(num);
console.log(num);
}
}
},
{
xtype:'button',
text:'5',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print 5");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("5");
}
else
{
num=num+"5";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
},
{
xtype:'button',
text:'6',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print 6");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("6");
}
else
{
num=num+"6";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
}
]
},
{
layout:'hbox',
style:'background-color:#A0A0A0',
flex:1,
items:[
{
xtype:'button',
text:'7',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 7");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("7");
}
else
{
num=num+"7";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
},
{
xtype:'button',
text:'8',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 8");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("8");
}
else
{
num=num+"8";
Ext.getCmp('display').setValue(num);
console.log(num);
}
}
},
{
xtype:'button',
text:'9',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 9");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("9");
}
else
{
num=num+"9";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
}
]
},
{
layout:'hbox',
style:'background-color:#808080',
flex:1,
items: [
{
xtype:'button',
text:'+',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
var num = new Array();
num=Ext.getCmp('display').getValue();
var len=num.length;
console.log(len);
var sub=num.substr(len-1,len);
console.log(sub);
if(sub!= "+" && sub!="-" && sub!="*" &&sub!="/")
{
num=num+"+";
Ext.getCmp('display').setValue(num);
}
console.log("print +");
}
},
{
xtype:'button',
text:'0',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print 0");
var num=Ext.getCmp('display').getValue();
if(num==0) {
num=num+"0";
Ext.getCmp('display').setValue(num);
}
else
{
num=num+"0";
Ext.getCmp('display').setValue(num);
console.log(num);
}
}
},
{
xtype:'button',
text:'=',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print =");
var exp=new Array();
exp=Ext.getCmp('display').getValue();
var len=exp.length;
var sub=exp.substr(len-1,len);
console.log(sub);
if(sub!= "+" && sub!="-" && sub!="*" && sub!="/")
{
console.log(eval(exp));
Ext.getCmp('display').setValue(eval(exp));
}
}
}
]
},
{
layout:'hbox',
style:'background-color:#2FAA96',
flex:1,
items: [
{
xtype:'button',
text:'-',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print -");
var num = new Array()
num=Ext.getCmp('display').getValue();
var len=num.length;
var sub=num.substr(len-1,len);
if(sub!= "+" && sub!="-" && sub!="*" &&sub!="/")
{
num=num+"-";
Ext.getCmp('display').setValue(num);
console.log("print -");
}
}
},
{
xtype:'button',
text:'*',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print *");
var num = new Array()
num=Ext.getCmp('display').getValue();
var len=num.length;
var sub=num.substr(len-1,len);
if(sub!= "+" && sub!="-" && sub!="*" &&sub!="/")
{
num=num+"*";
Ext.getCmp('display').setValue(num);
console.log("print *");
}
}
},
{
xtype:'button',
text:'/',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print /");
var num = new Array()
num=Ext.getCmp('display').getValue();
var len=num.length;
var sub=num.substr(len-1,len);
if(sub!= "+" && sub!="-" && sub!="*" &&sub!="/")
{
num=num+"/";
Ext.getCmp('display').setValue(num);
console.log("print /");
}
}
},
]
},
{
layout:'hbox',
flex:8,
style:'background-color:red',
items: [
{
xtype:'button',
text:'clear',
style:'border:5px inset blue',
flex:1,
ui:'small',
handler: function() {
var cl=Ext.getCmp('display').getValue();
cl="";
Ext.getCmp('display').setValue(cl);
}
},
{
xtype:'button',
text:'cancel',
flex:2,
ui:'back',
handler:function() {
var no= new Array();
no=Ext.getCmp('display').getValue();
var len=no.length;
var sub=no.slice(0,len-1)
console.log(sub);
Ext.getCmp('display').setValue(sub);
}
}
]
}
]
}
});

Related

Existing Custom Rally App is producign results as expected

I got the below reference of CustomHTML App for Rally and added into my custom report page in my project workspace. UI Worked, but somehow whatever simple query I give in, there is no result shown. Please review and correct me if I am doing any wrong.
Find fixed defects within certain dates
<script type="text/javascript" src="/apps/2.0rc1/sdk.js"></script>
<script type="text/javascript">
Rally.onReady(function() {
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
layout: {
type: 'vbox',
align: 'stretch'
},
items:[
{
xtype: 'panel',
layout: 'anchor',
border: true,
fieldDefaults: {
labelWidth: 40
},
defaultType: 'textfield',
bodyPadding: 5,
items: [
{
fieldLabel: 'Query',
itemId: 'queryField',
anchor:'100%',
width: 700,
height: 100,
xtype: 'textarea',
value: '{\n'+
' "_TypeHierarchy": "Defect",\n'+
'"__At": "2016-10-14T00:00:00Z"'+
'}'
},
{
fieldLabel: 'Fields',
itemId: 'fieldsField',
anchor: '100%',
width: 700,
value: "ObjectID, _ValidFrom, Name, State, Resolution"
},
{
fieldLabel: 'Sort',
itemId: 'sortField',
anchor: '100%',
width: 700,
value: "{'ObjectID' : -1, '_ValidFrom': 1}"
},
{
fieldLabel: 'Page Size',
itemId: 'pageSizeField',
anchor: '100%',
width: 700,
value: '10'
},
{
fieldLabel: 'Hydrate',
itemId: 'hydrate',
anchor: '100%',
width: 700,
value: "State, Resolution"
},
],
buttons: [
{
xtype: 'rallybutton',
text: 'Search',
itemId: 'searchButton'
}
]
},
{
xtype: 'panel',
itemId: 'gridHolder',
layout: 'fit',
height: 400
}
],
launch: function() {
var button = this.down('#searchButton');
button.on('click', this.searchClicked, this);
},
searchClicked: function(){
var queryField = this.down('#queryField');
var query = queryField.getValue();
var selectedFields = this.down('#fieldsField').getValue();
if(selectedFields){
if(selectedFields === 'true'){
selectedFields = true;
}
else{
selectedFields = selectedFields.split(', ');
}
}
var sort = this.down('#sortField').getValue();
var pageSize = this.down('#pageSizeField').getValue();
var parsedPageSize = parseInt(pageSize, 10);
// don't allow empty or 0 pagesize
pageSize = (parsedPageSize) ? parsedPageSize : 10;
var callback = Ext.bind(this.processSnapshots, this);
this.doSearch(query, selectedFields, sort, pageSize, callback);
},
createSortMap: function(csvFields){
var fields = csvFields.split(', ');
var sortMap = {};
for(var field in fields){
if(fields.hasOwnProperty(field)){
sortMap[field] = 1;
}
}
return sortMap;
},
doSearch: function(query, fields, sort, pageSize, callback){
var transformStore = Ext.create('Rally.data.lookback.SnapshotStore', {
context: {
workspace: this.context.getWorkspace(),
project: this.context.getProject()
},
fetch: fields,
find: query,
autoLoad: true,
hydrate: ["State","Resolution"],
listeners: {
scope: this,
load: this.processSnapshots
}
});
},
processSnapshots: function(store, records){
var snapshotGrid = Ext.create('Rally.ui.grid.Grid', {
title: 'Snapshots',
store: store,
columnCfgs: [
{
text: 'ObjectID',
dataIndex: 'ObjectID'
},
{
text: 'Name',
dataIndex: 'Name'
},
{
text: 'Project',
dataIndex: 'Project'
},
{
text: '_ValidFrom',
dataIndex: '_ValidFrom'
},
{
text: '_ValidTo',
dataIndex: '_ValidTo'
},
{
text: 'State',
dataIndex: 'State'
},
{
text: 'Resolution',
dataIndex: 'Resolution'
},
],
height: 400
});
var gridHolder = this.down('#gridHolder');
}
gridHolder.removeAll(true);
gridHolder.add(snapshotGrid);
});
Rally.launchApp('CustomApp', {
name: 'lbapi'
});
});
</script>
<style type="text/css">
.app {
/* Add app styles here */
}
</style>
</head>
<body></body>
</html>
There were a couple syntax errors in the posted code above. It was also written using a super old version of the sdk. I updated to the latest 2.1 and it seems to work pretty well now. More than likely most of the issues with the old app was the Lookback API request timing out. The new SDK has a longer default timeout.
<!DOCTYPE html>
<html>
<head>
<title>Lookback API Query</title>
<script type="text/javascript" src="/apps/2.1/sdk.js"></script>
<script type="text/javascript">
Rally.onReady(function() {
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'panel',
layout: 'anchor',
border: true,
fieldDefaults: {
labelWidth: 40
},
defaultType: 'textfield',
bodyPadding: 5,
items: [{
fieldLabel: 'Query',
itemId: 'queryField',
anchor: '100%',
width: 700,
height: 100,
xtype: 'textarea',
value: '{\n' +
' "_TypeHierarchy": "Defect",\n' +
'"__At": "2016-10-14T00:00:00Z"\n' +
'}'
}, {
fieldLabel: 'Fields',
itemId: 'fieldsField',
anchor: '100%',
width: 700,
value: "ObjectID, _ValidFrom, Name, State, Resolution"
}, {
fieldLabel: 'Sort',
itemId: 'sortField',
anchor: '100%',
width: 700,
value: "{'ObjectID' : -1, '_ValidFrom': 1}"
}, {
fieldLabel: 'Page Size',
itemId: 'pageSizeField',
anchor: '100%',
width: 700,
value: '10'
}, {
fieldLabel: 'Hydrate',
itemId: 'hydrate',
anchor: '100%',
width: 700,
value: "State, Resolution"
}, ],
buttons: [{
xtype: 'rallybutton',
text: 'Search',
itemId: 'searchButton'
}]
}, {
xtype: 'panel',
itemId: 'gridHolder',
layout: 'fit',
height: 400
}],
launch: function() {
var button = this.down('#searchButton');
button.on('click', this.searchClicked, this);
},
searchClicked: function() {
var queryField = this.down('#queryField');
var query = queryField.getValue();
var selectedFields = this.down('#fieldsField').getValue();
if (selectedFields) {
if (selectedFields === 'true') {
selectedFields = true;
} else {
selectedFields = selectedFields.split(', ');
}
}
var sort = this.down('#sortField').getValue();
var pageSize = this.down('#pageSizeField').getValue();
var parsedPageSize = parseInt(pageSize, 10);
// don't allow empty or 0 pagesize
pageSize = (parsedPageSize) ? parsedPageSize : 10;
var callback = Ext.bind(this.processSnapshots, this);
this.doSearch(query, selectedFields, sort, pageSize, callback);
},
createSortMap: function(csvFields) {
var fields = csvFields.split(', ');
var sortMap = {};
for (var field in fields) {
if (fields.hasOwnProperty(field)) {
sortMap[field] = 1;
}
}
return sortMap;
},
doSearch: function(query, fields, sort, pageSize, callback) {
var transformStore = Ext.create('Rally.data.lookback.SnapshotStore', {
context: {
workspace: this.context.getWorkspace(),
project: this.context.getProject()
},
fetch: fields,
pageSize: pageSize,
find: query,
autoLoad: true,
hydrate: ["State", "Resolution"],
listeners: {
scope: this,
load: this.processSnapshots
}
});
},
processSnapshots: function(store, records) {
var snapshotGrid = Ext.create('Rally.ui.grid.Grid', {
title: 'Snapshots',
store: store,
columnCfgs: [{
text: 'ObjectID',
dataIndex: 'ObjectID'
}, {
text: 'Name',
dataIndex: 'Name'
}, {
text: 'Project',
dataIndex: 'Project'
}, {
text: '_ValidFrom',
dataIndex: '_ValidFrom'
}, {
text: '_ValidTo',
dataIndex: '_ValidTo'
}, {
text: 'State',
dataIndex: 'State'
}, {
text: 'Resolution',
dataIndex: 'Resolution'
}, ],
height: 400
});
var gridHolder = this.down('#gridHolder');
gridHolder.removeAll(true);
gridHolder.add(snapshotGrid);
}
});
Rally.launchApp('CustomApp', {
name: 'lbapi'
});
});
</script>
<style type="text/css">
.app {
/* Add app styles here */
}
</style>
</head>
<body></body>
</html>

Click event not getting registered from within a controller in ExtJS 4 MVC

My button click event subscribed in the controller is getting fired. Here is the code.
WebAppMasterController.js
Ext.define('P.e.w.controller.WebAppMasterController', {
extend: 'P.e.w.controller.IController',
views: [
'WebAppMasterView'
],
refs: [
{
ref: 'webAppView',
selector: 'WebAppMasterView'
}
],
init: function () {
this.control({
'WebAppMasterView': {
afterrender: this.viewafterrender
}
}, {
'button[action=save]': {
click: function () {
alert('dslksd');
}
}
}
},
viewafterrender: function (panel) {
alert();
}
});
IController extends "Ext.app.Controller".
In the above code, the "afterrender" event is getting triggered, but the button click event is not getting triggered.
The view: WebAppMasterView.js
Ext.define('P.e.w.view.WebAppMasterView', {
extend: 'P.w.l.Header',
alias: 'widget.WebAppMasterView',
constructor: function (config) {
var me = this;
me.centerregion = me.createCenterRegion(config);
Ext.applyIf(config, {
favoriteBar: true,
items: [me.centerregion],
menuWidth: 0
});
this.callParent([config]);
},
createBody: function () {
var me = this;
if (!me.controlPanel) {
me.controlPanel = Ext.create('Ext.Panel', {
layout: 'fit'
});
}
return me.controlPanel;
},
createCenterRegion: function (config) {
var me = this,
centerPanel = Ext.create('Ext.Panel', {
region: 'center',
layout: 'fit',
tbar: {
xtype: 'WorkRequestMenuBar',
id: 'workrequestmenubar'
},
defaults: {
border: false
},
items: [me.createBody()]
});
return centerPanel;
}
});
WorkRequestMenuBar.js
Ext.define('P.e.w.view.WorkRequestMenuBar', {
extend: 'Ext.Toolbar', alias: 'widget.WorkRequestMenuBar',
constructor: function (config) {
config = config || {};
Ext.apply(config, {
defaults: {
scale: 'large',
cls: 'x-btn-text-icon',
iconAlign: 'top'
},
items: [
{
text: 'NEW_WORK_REQUEST',
iconCls: 'menubar-createWorkRequest',
action: 'save'
},
{
text: 'OVERVIEW',
iconCls: 'menubar-overview'
}, '->', {
iconCls: 'icon-biggerHelp',
width: 80,
text: 'HELP'
}
]
});
this.callParent([config]);
}
});
You have several issues.
1st. there is a syntax error in your controller
this.control({
'WebAppMasterView': {
afterrender: this.viewafterrender
}
},
{
'button[action=save]': {
click: function () {
alert('dslksd');
}
}
}
//missing --> );
},
2nd. The toolbar config method should be initComponent method instead.

aligment of keypad buttons(numbers)

I'm new to sencha touch.I wrote code for number keypad,but the buttons are displayed vertically.my code is
Ext.define("exercise.view.Numberplate",{
extend: "Ext.SegmentedButton",
requires:['Ext.Button'],
xtype:'Numberplate',
allowMultiple: true,
config: {
pack:'center',
centered:true,
height:30,
width:100,
xtype:'button',
items: [
{
xtype:'segmentedbutton',
allowDepress:true,
scroll:true,
//layout:'vbox',
items:[
{
text:'1',
width:100
},
{
text : '2',
width:100
},
{
text: '3',
width:100
}
]
},
{
xtype:'segmentedbutton',
//centered:true,
pack:'center',
items:[
/* {
centered:true,
html: [
'<br><br><br><br>'
].join("")
},*/
{
text:'4',
width:100
},
{
text:'5',
width:100
},
{
text:'6',
width:100
}
]
}
]
},
constructor: function() {
this.on({
scope: this,
delegate: 'button',
tap: 'tapHandler'
});
this.callParent(arguments);
},
tapHandler: function(button) {
alert(button.getText());
// this.setHtml("<span class=action>User tapped " + button.getText() + "</span>");
}
});
I tried ,but i didnt get this .I think it's easy but i don't know how to do this.can anyone help me.thanks in advance
Just add layout:vbox to your config:
Ext.define("exercise.view.Numberplate",{
extend: "Ext.SegmentedButton",
requires:['Ext.Button'],
xtype:'Numberplate',
allowMultiple: true,
config: {
layout: 'vbox', // Add right here
pack:'center',
centered:true,
height:30,
width:100,
xtype:'button',
items: [
{
xtype:'segmentedbutton',
allowDepress:true,
scroll:true,
//layout:'vbox',
items:[
{
text:'1',
width:100
},
{
text : '2',
width:100
},
{
text: '3',
width:100
}
]
},
{
xtype:'segmentedbutton',
//centered:true,
pack:'center',
items:[
/* {
centered:true,
html: [
'<br><br><br><br>'
].join("")
},*/
{
text:'4',
width:100
},
{
text:'5',
width:100
},
{
text:'6',
width:100
}
]
}
]
},
constructor: function() {
this.on({
scope: this,
delegate: 'button',
tap: 'tapHandler'
});
this.callParent(arguments);
},
tapHandler: function(button) {
alert(button.getText());
// this.setHtml("<span class=action>User tapped " + button.getText() + "</span>");
}
});
Hope it helps :)

Remove a record from a Grid Locally

I have a Grid in a Window. When i click on a row of that window and click on the remove button, that row should get removed from the window. (I think i will have to remove it from Store and reload the grid, so the changes will be picked)
I am unable to get the click event and remove the row from the store. I have added the button for this but not able to get the Grid record and remove it from store and reloading it.
My code is as follows;
Ext.define('MyApp.view.Boy', {
extend: 'Ext.window.Window',
alias: 'widget.boy',
height: 800,
width: 900,
layout: {
type: 'absolute'
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'gridpanel',
height: 500,
width: 800,
title: 'My Grid Panel',
store: 'School',
viewConfig: {
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'Id',
text: 'id'
},
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'name'
}
]
},
{
xtype: 'button',
height: 40,
width: 150,
text: 'Remove',
listeners: {
click: {
fn: me.removebuttonclick,
scope: me
}
}
}
]
});
me.callParent(arguments);
},
removebuttonclick: function(button, e, options) {
console.log('removebuttonclick');
}
});
Something like:
Ext.define('MyApp.view.Boy', {
extend: 'Ext.window.Window',
alias: 'widget.boy',
height: 800,
width: 900,
layout: {
type: 'absolute'
},
initComponent: function() {
var me = this;
var this.grid = Ext.widget({
xtype: 'gridpanel',
height: 500,
width: 800,
title: 'My Grid Panel',
store: 'School',
viewConfig: {
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'Id',
text: 'id'
},
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'name'
}
]
});
Ext.applyIf(me, {
items: [
this.grid, //oopsie
{
xtype: 'button',
height: 40,
width: 150,
text: 'Remove',
listeners: {
click: {
fn: me.removebuttonclick,
scope: me
}
}
}
]
});
me.callParent(arguments);
},
removebuttonclick: function(button, e, options) {
var me = this;
Ext.Array.each(this.grid.getSelectionModel().selected,function(record, index,selectedRows){
me.grid.getStore().remove(record);
});
}
});

Create DataItem in Dataview Sencha Touch 2

I need create a dataview component with the following structure
Structure
I learned how to create simple text component, but this structure is more difficult.
I use this code, but is only the name field
Ext.define('DEMO.view.product.ListItem', {
extend: 'Ext.dataview.component.DataItem',
xtype: 'product-list-item',
config: {
cls: 'product-list-item',
dataMap: {
getName: {
setHtml: 'name'
}
},
name: {
cls: 'x-name',
flex: 1
},
layout: {
type: 'hbox',
align: 'left'
}
},
applyName: function(config){
return Ext.factory(config, Ext.Component, this.getName());
},
updateName: function(newName, oldName) {
if (newName) {
this.add(newName);
}
if (oldName) {
this.remove(oldName);
}
}
});
Just need to add the other components as the name. For example,
Ext.define('App.view.UserItem', {
extend: 'Ext.dataview.component.DataItem',
xtype: 'useritem',
config: {
cls: 'user-item',
firstName: { cls: 'first-name', flex: 1 },
lastName: { cls: 'last-name', flex: 2 },
layout: { type: 'hbox', align: 'center' },
dataMap: {
getFirstName: { setHtml: 'firstName' },
getLastName: { setHtml: 'lastName' }
}
},
applyFirstName: function(config) {
return Ext.factory(config, Ext.Component, this.getFirstName());
},
updateFirstName: function(newFirstName, oldFirstName) {
if(newFirstName) this.add(newFirstName);
if(oldFirstName) this.remove(oldFirstName);
},
applyLastName: function(config) {
return Ext.factory(config, Ext.Component, this.getLastName());
},
updateLastName: function(newLastName, oldLastName) {
if(newLastName) this.add(newLastName);
if(oldLastName) this.remove(oldLastName);
}
});
For more detail, please visit http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2/