Sencha 2 - displaying null value in nested List - sencha-touch-2

I am new to sencha. I am developing an app using treestore and nestedList.
I am unable to load data returned from a coldfusion component.it shows null.
Here is my Viewport.js:
Ext.define('Myapp.view.Viewport', {
extend: 'Ext.tab.Panel',
xtype:'newviewport',
config: {
fullscreen: true,
tabBarPosition: 'top',
html: 'hiiiiiiiiiii',
cls:'test',
items: [
{
title: 'Sections',
iconCls: 'home',
xtype: 'sectionslist'
}
]
}
});
My store:samplestore.js
Ext.define('Myapp.store.samplestore', {
extend: 'Ext.data.TreeStore',
config: {
autoLoad: true,
model: 'Myapp.model.sampleModel',
proxy: {
type: 'ajax',
url: '/sample/sample1.cfc?method=getSections',
reader: {
type: 'json',
rootProperty:'DATA'
}
}
}
});
My model: sampleModel.js
Ext.define("Myapp.model.sampleModel", {
extend: "Ext.data.Model",
config: {
fields: [
{name: 'LoginID', type: 'string'},
{name: 'FIRSTNAME', type: 'string'}
]
}
});
My sample1.cfc :
<cfcomponent name="sample" output="false">
<cffunction name="getSections" output="no" returnformat="json" access="remote">
<cfquery name="qryGetDetails" datasource="#request.dsn#">
SELECT TOP 5
LoginID, FIRSTNAME
FROM
tblUser
</cfquery>
<cfreturn qryGetDetails>
</cffunction>
</cfcomponent>
My Sectionslist.js
Ext.define('Myapp.view.Sectionslist', {
extend: 'Ext.dataview.NestedList',
xtype: 'sectionslist',
config: {
store: 'samplestore'
itemTpl: [
'{FIRSTNAME}<br/>'
].join(''),
onItemDisclosure: function(record, btn, index) {
console.log("worked");
}
},
//getItemTextTpl: function(node) {
//console.log(node);
// return node.data.FIRSTNAME+ ':<strong></strong>';
// }
});
And finally my json data:
{"COLUMNS":["LOGINID","FIRSTNAME"],"DATA":[["bt","Jn"],["jr","Jy"],["b20","Best"],["jman","Jeff"],["fenad","Fn"]]}
PLease help to find out my problem, I cant trigger where i went wrong, I am getting null value, as displaying data is wrong.:
itemTpl: [
'{FIRSTNAME}'
].join(''),
Instead of Firstname ,what should i display here??? I tried many methods, but no use, please help.....

Your JSON is returning a collection of Arrays like
["bhpAgent", "Jan"],
but the field definition expects the response to be a collection of objects like
{"LoginID": "bhpAgent", "FIRSTNAME": "Jan"}.
Not sure of the best solution. Can ColdFusion generate JSON objects instead?
If not, maybe subclass Ext.data.reader.JSON and override getResponseData().
Might also be worth checking the TreeStore docs as that view has a further requirement for tree structured data.

Related

Pushing a new view after an item was tapped in Sencha Touch 2

I have a simple list populated from json. When tapping one of the items i want a new view to appear. The List is inside an Ext.navigation.View.
My controller
Ext.define('Trainz.controller.StationListController', {
extend: 'Ext.app.Controller',
config: {
models: [
'Station'
],
stores: [
'Stations'
],
views: [
'Main'
],
control: {
"list": {
itemtap: 'onListItemTap'
}
}
},
onListItemTap: function(dataview, index, target, record, e, eOpts) {
console.log(record);
}
});
And here is the (now empty) view i want to push
Ext.define('Trainz.view.StationDetailView', {
extend: 'Ext.Panel',
config: {
}
});
Guessing i have to put something in the onListItemTap function but for the life of me I cant figure out what. Tried over four different code snippets from Google and just got errors back. Whats the proper way?
I'm using Sencha Architect if that makes any difference.
Here is the complete initial view for reference:
Ext.define('Trainz.view.Main', {
extend: 'Ext.tab.Panel',
config: {
tabBar: {
docked: 'bottom'
},
items: [
{
xtype: 'navigationview',
title: 'Stations',
iconCls: 'maps',
items: [
{
xtype: 'list',
title: 'Stations',
itemTpl: [
'<div>{Namn}</div><div style="float:right; margin-right: 1.5em;"></div>'
],
store: 'Stations',
grouped: true,
indexBar: true
}
]
}
]
}
});
You need need to retrieve your navigationview and then do
navigationView.push(yourNewView);
or
dataview.up('navigationview').push(yourNewView)
http://docs.sencha.com/touch/2.2.0/#!/api/Ext.navigation.View-method-push
Hope this helps

Can not fetch store data from table layout in extjs 4

I am trying to fetch data from store.and i want to use it on my table layout in an extjs panel but always get an empty string though the data is printed in the console. Any pointers would be much appreciated.
<code>
Ext.onReady(function(){
Ext.define('Account', {
extend: 'Ext.data.Model',
fields: [
'id',
'name',
'nooflicenses'
]
});
var store = Ext.create('Ext.data.Store', {
model: 'Account',
autoSync: true,
proxy: {
type: 'ajax',
api: {
read: "accounts"
},
reader: {
type: 'json',
root: 'Account',
successProperty: 'success',
messageProperty: 'message',
totalProperty: 'results',
idProperty: 'id'
},
listeners: {
exception: function(proxy, type, action, o, result, records) {
if (type = 'remote') {
Ext.Msg.alert("Could not ");
} else if (type = 'response') {
Ext.Msg.alert("Could not " + action, "Server's response could not be decoded");
} else {
Ext.Msg.alert("Store sync failed", "Unknown error");}
}
}//end of listeners
}//end of proxy
});
store.load();
store.on('load', function(store, records) {
for (var i = 0; i < records.length; i++) {
console.log(store.data.items[0].data['name']); //data printed successfully here
console.log(store.getProxy().getReader().rawData);
console.log(store);
};
});
function syncStore(rowEditing, changes, r, rowIndex) {
store.save();
}
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false,
saveText: 'Save',
listeners: {
afteredit: syncStore
}
});
var grid = Ext.create('Ext.panel.Panel', {
title: 'Table Layout',
width: 500,
height:'30%',
store: store,
layout: {
type: 'table',
// The total column count must be specified here
columns: 2,
tableAttrs: {
style: {
width: '100%',
height:'100%'
}
},
tdAttrs: {
style: {
height:'10%'
}
}
},
defaults: {
// applied to each contained panel
bodyStyle:'border:0px;',
xtype:'displayfield',
labelWidth: 120
},
items: [{
fieldLabel: 'My Field1',
name :'nooflicenses',
value: store //How to get the data here
//bodyStyle:'background-color:red;'
},{
fieldLabel: 'My Field',
name:'name',
value:'name'
}],
renderTo: document.getElementById("grid1")
});
});
</code>
Ext.grid.Panel control is totally configurable so it allows to hide different parts of the grid. In our case the way to hide a headers is adding property: hideHeaders:
Ext.create("Ext.grid.Panel", {
hideHeaders: true,
columns: [ ... ],
... other options ...
});
If you still would like to adopt another solution, the more complex solution I have think about is the use of XTemplate for building table dynamically. (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.XTemplate). In this approach you write the template describing how the table will be built.
Otherwise, I still recommend you to deal with the former solution rather than the latter one. The latter approach opposes the basic idea of Sencha ExtJS: use ExtJS library's widgets, customize them in the most flexible way and then automate them by creating store and model.
The most "native" way to show data is by use Ext.grid.Panel.
Example:
Ext.application({
name: 'LearnExample',
launch: function() {
//Create Store
Ext.create ('Ext.data.Store', {
storeId: 'example1',
fields: ['name','email'],
autoLoad: true,
data: [
{name: 'Ed', email: 'ed#sencha.com'},
{name: 'Tommy', email: 'tommy#sencha.com'}
]
});
Ext.create ('Ext.grid.Panel', {
title: 'example1',
store: Ext.data.StoreManager.lookup('example1'),
columns: [
{header: 'Name', dataIndex: 'name', flex: 1},
{header: 'Email', dataIndex: 'email', flex: 1}
],
renderTo: Ext.getBody()
});
}
});
The grid can be configured in the way it mostly customized for user's needs.
If you have a specific reason why to use Ext.panel.Panel with a table layout, you can use XTemplate, but it more complicate to bind the data.

Sencha Touch Ext.List does not fill with the data of store

Ext.List does not fill with the data of store, only shows two lines of empty list item. When I debug with firebug, I saw store is filled with the information in json data but list items does not shown.
Store object
Ext.define('MyApp.store.ListStore', {
extend: 'Ext.data.Store',
autoLoad: true,
config:
{
model: 'MyApp.model.NewsData',
fields: [{ name: 'haberId', mapping: 'haberId' },
{ name: 'haberGonderen', mapping: 'haberGonderen' },
{ name: 'haberDetay', mapping: 'haberDetay' },
{ name: 'haberZaman', mapping: 'haberZaman'}]
},
proxy: {
id: 'ListStore',
access: 'public'
}});
News object
Ext.define('MyApp.model.NewsData', {
extend: "Ext.data.Model",
config: {
fields: [
'haberId',
'haberGonderen',
'haberDetay',
'haberZaman'
]
}});
List View
Ext.define('MyApp.view.ListTemplate', {
extend: 'Ext.List',
title: 'Haber Listesi',
store : 'ListStore',
fullscreen: true,
itemTpl : '{haberGonderen}'});
Anybody has any idea?
Try this. May be this helps you.
Store.js
Ext.define('MyApp.store.ListStore', {
extend: 'Ext.data.Store',
config:
{
autoLoad: true,
model: 'MyApp.model.NewsData',
proxy: {
id: 'ListStore',
access: 'public'
},
fields: [{ name: 'haberId', mapping: 'haberId' },
{ name: 'haberGonderen', mapping: 'haberGonderen' },
{ name: 'haberDetay', mapping: 'haberDetay' },
{ name: 'haberZaman', mapping: 'haberZaman'}]
}
});
ListTemplate.js
Ext.define('MyApp.view.ListTemplate', {
extend: 'Ext.List',
config: {
fullscreen: true,
title: 'Haber Listesi',
store : 'ListStore',
itemTpl : '{haberGonderen}'
}
});

Sencha Formfields passing empty fields

I'm learning Sencha Touch. I created this app with a form before and it worked fine.
Now i'm working on a new little test app i copy the code from the other app and it only passes empty variables to the webservice.
the View:
<!-- language: lang-js -->
Ext.define('Gasoline.view.InsertTankTrip', {
requires: [
'Ext.form.FieldSet'
],
extend: 'Ext.form.Panel',
xtype: 'inserttankpanel',
id: 'insertTankForm',
config: {
title: 'Insert Tank Trip',
iconCls: 'add',
url: 'contact.php',
items:[
{
xtype: 'fieldset',
title: 'Insert Tank Trip',
instructions: '(Make sure the info is correct!)',
items:[
{
xtype: 'datepickerfield',
label: 'Date',
name: 'date',
value: new Date()
},
{
xtype: 'textfield',
label: 'Amount',
name: 'amount',
minValue:-9007199254740992,
maxValue: 9007199254740992
}
]
},{
xtype: 'button',
text: 'Send',
ui: 'confirm',
action: 'insertTankSubmit'
}
]
}
});
And in the controller :
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add(Ext.create('Gasoline.view.Main'));
this.control({
'button[action=insertTankSubmit]' : {
tap: 'insertTankForm'
}/*,
'list[itemId=kingsLeagueList]' : {
itemtap: 'onListTap'
},
'list[itemId=tournamentsList]' : {
disclose: 'showDetail'
}*/
});
},
insertTankForm : function(){
console.log('test');
var form = this.getInsertTankForm();
form.submit({
url:'contact.php'
});
},
This sends the following to the webservice (which currently doesn't exist i just check with developer tools)
date:2012-07-26T17:02:16
amount:
so the date does get sent , the number doesnt
If i fill in a standard value for the number ... that gets sent but if you type something in , it still doesn't send that
Use
xtype: 'numberfield'
instead of
xtype: 'textfield'
I had tried numerous solutions...none of them worked.
Lastly i deleted everything ... coded everything the exact same way and it started working ...

how to make visible list in sencha touch2

i am new to sencha touch2. i want display list in a page. binding is happening successful. but i am not able to see data but able to scroll page. please any one can help me. i facing this issue. thank you.
My code is here:
Ext.define("Sencha.view.ProjectListView", {
extend: 'Ext.form.Panel',
xtype: 'projectListepage',
id: 'projectListepage',
requires: [
'Ext.data.JsonP'
],
config: {
scrollable: true,
items: [{
xtype: 'panel',
id: 'JSONP'
},
{
docked: 'top',
xtype: 'toolbar',
flex: 3,
items: [{
text: 'Project Deatils',
handler: function () {
var list = Ext.getCmp('JSONP'),
tpl = new Ext.XTemplate([
'<tpl for=".">',
'<img src="{MainImageUrl}"/><label>{ProjectName}</label><p class="temp_low">{ShortDescription}</p>', //
'</tpl>',
]);
Ext.data.JsonP.request({
url: 'http://localhost:53985/PropertyService.svc/GetAllProject',
callbackKey: 'callback',
params: {
},
callback: function (success, request) {
var project = request;
if (project) {
list.updateHtml(tpl.applyTemplate(project));
}
else {
alert('There was an error retrieving the weather.');
}
}
});
}
}]
}]
}
});
I do not see anywhere in your code sample where you are creating a list. You need to extend 'Ext.List' or use xtype:'list'. There are a few simple examples in the sencha touch 2 docs on how to create a list. http://docs.sencha.com/touch/2-0/#!/api/Ext.dataview.List