Implementing paging for sencha touch list - html

I have following sample application, where i am trying to implement paging functionality for sencha touch , but i am facing issues in setting the page size and when i hit load more same old data is being repeated in the list, please can i know where i am going wrong ?
Ext.define("WEB.view.SearchView", {
extend: 'Ext.dataview.List',
xtype: 'SearchView',
requires: [
'Ext.dataview.List',
'Ext.data.Store',
'Ext.List'
],
config: {
title: 'Search Results',
plugins: [
{
xclass: 'Ext.plugin.ListPaging',
autoPaging: false,
loadMoreText: 'Loading...',
noMoreRecordsText: 'No More Records'
},
{ xclass: 'Ext.plugin.PullRefresh' }
],
//onItemDisclosure: false,
store: {
id: 'MySearchStore',
autoLoad:false,
pageSize: 15,
clearOnPageLoad: false,
fields: [
{ name: "ShortDescription", type: "string" },
{ name: "MatchId", type: "bool" }
],
proxy: {
type: 'jsonp',
url: 'http://Example.com',
reader: {
type: 'json',
rootProperty: 'd'
}
}
},
itemTpl: new Ext.XTemplate('<tpl if="MatchId == 1">', '<p style="color: #ff9900">{BlockNo}</p><p>{ShortDescription}</p>', '</tpl>',
'<tpl if="MatchId == 0">', '<p >{BlockNo}</p><p>{ShortDescription}</p>', '</tpl>'
)
}
});

This is a simple issue but can be a bottleneck when you are starting out...
Set the pageParam in the store to what you use for pagination on the server side... Then everything should work fine...
Note: Your actual pagination logic should be on the server side... Sencha only provides a means to display the content a few at a time...
Ext.define('MyApp.store.MyJsonStore', {
extend: 'Ext.data.Store',
config: {
storeId: 'MyJsonStore',
proxy: {
type: 'ajax',
pageParam: 'page',//This parameter needs to be modified
reader: {
type: 'json'
}
}
}
});

Related

Can't get 'hasMany' data from nest JSON

I have a nested JSON and I cannot seem to extract the nested array. I am not sure if I set up my store and models correctly. It seems right. As you can see at the bottom of this post, when I try to get the nested part out, it doesn't work.
JSON data:
{
"data":{
"name":"John",
"age":"23",
"gender":"Male",
"purchase":[
{
"item":"shirt",
"qty":1,
"price":10
},
{
"item":"hat",
"qty":2,
"price":25
},
{
"item":"pants",
"qty":1,
"price":15
}
]
},
"success":true,
"errorMsg":""
}
Store:
Ext.define('Pvm.store.MyStore', {
extend: 'Pvm.store.PvmBaseStore',
requires: [
'Pvm.model.Customer'
],
model: 'Pvm.model.Customer',
autoLoad: false
});
Customer Model:
Ext.define('Pvm.model.Customer', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.Field',
'Ext.data.proxy.Ajax',
'Ext.data.reader.Json'
],
fields: [{
name: 'name',
type: 'auto'
}, {
name: 'age',
type: 'auto'
}, {
name: 'gender',
type: 'auto'
}],
associations: {
type: 'hasMany',
model: 'Pvm.model.Purchase',
name: 'purchase',
associationKey: 'purchase'
},
proxy: {
type: 'ajax',
actionMethods: {
create: 'POST',
read: 'POST', // changed read's method to POST (from GET) so we get the parameters as form data (not in URL, for security reasons)
update: 'POST',
destroy: 'POST'
},
url: '/pvmsvr/uiapi?cmd=readXml',
reader: {
type: 'json',
rootProperty: 'data'
}
}
});
Purchase Model:
Ext.define('Pvm.model.Purchase', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.Field',
'Ext.data.proxy.Ajax',
'Ext.data.reader.Json'
],
fields: [{
name: 'item',
type: 'auto'
}, {
name: 'qty',
type: 'auto'
}, {
name: 'price',
type: 'auto'
}],
associations: {
type: 'belongsTo',
model: 'Pvm.model.Customer'
}
});
Controller Code:
onStoreLoaded: function(store, records, successful, eOpts) {
console.log(store); // works
console.log(records); // works
console.log(records[0].get('name')); // works
console.log(records[0].purchase(); // doesn't work; returns 'undefined'
}
I am idiot. I needed the child model's class name in the parent's requires...

Sencha Touch JsonP Request TypeError Ext.data is undefined

at the moment I'm working on my first Sencha Touch Application and I run into a problem I spent lots of hours until now.
I tried to get the value from a cross domain Json to fill a nested list in my application.
When I run my code in browser everything works fine. The List is filled and I can call a detail view by tap on a leafitem.
But after building the sencha touch app with "sencha app build", I only get the following error in the browser console when starting the app.
TypeError: Ext.data is undefined
Ext.data.JsonP.callback1({ Here is the long valid JSON content });
I don't unterstand, why Ext.data is undefined. I would appreciate if someone could help me. I tried several solutions but I couldn't get this running.
These are the contents of my files:
Store:
Ext.define("Test.store.ExpStore", {
extend: "Ext.data.TreeStore",
requires: [
'Ext.data.JsonP'
],
config: {
model: "Test.model.ExpModel",
proxy: {
type: 'jsonp',
url: 'http://myurl/project/mylist.php',
callbackKey: 'callback',
reader: {
type: 'json',
rootProperty: 'experts'
}
}
}});
Model:
Ext.define('Test.model.ExpModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'name', type: 'string'},
{name: 'number', type: 'string'},
{name: 'active', type: 'boolean'}
]
}});
ListView:
Ext.define('Test.view.ExpListView', {
extend: 'Ext.NestedList',
alias: 'widget.expListView',
config: {
fullscreen: true,
title: "Experts",
displayField: 'name',
store: 'ExpStore',
}});
app.json
"js": [
{
"path": "touch/sencha-touch.js",
"x-bootstrap": true
},
{
"path": "bootstrap.js",
"x-bootstrap": true
},
{
"path": "app.js",
"bundle": true, /* Indicates that all class dependencies are concatenated into this file when build */
"update": "delta"
}],
app.js
Ext.application({
name: 'Test',
requires: [
'Ext.MessageBox',
//'Ext.data.JsonP',
'Ext.data.*'
],
models: [
'ExpModel'
],
views: [
//'Main'
'ExpDetailsView',
'ExpListView'
],
controllers: [
'ExpController'
],
stores: [
'ExpStore'
],
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon#2x.png',
'144': 'resources/icons/Icon~ipad#2x.png'
},
isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg',
'640x920': 'resources/startup/640x920.png',
'768x1004': 'resources/startup/768x1004.png',
'748x1024': 'resources/startup/748x1024.png',
'1536x2008': 'resources/startup/1536x2008.png',
'1496x2048': 'resources/startup/1496x2048.png'
},
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
var expListView = {
xtype: 'expListView'
};
var expDetailsView = {
xtype: 'expDetailsView'
};
// Initialize the main view
Ext.Viewport.add(expListView, expDetailsView);
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function(buttonId) {
if (buttonId === 'yes') {
window.location.reload();
}
}
);
}});

Extjs 5 XTemplate with JSON store data

I need help with my xtemplate and store with proxy. No matter what I am trying, I am stuck in this problem. The xtemplate is only showing data from a store without using a proxy.
Working store:
Ext.create('Ext.data.Store', {
storeId : 'viewStore',
model : 'dataview_model',
data : [
{statistic: '213213', description: 'Hallo'},
{statistic: '534345', description: 'Alloh'},
]
});
Working Xtemplate and data config
xtype: 'component',
cls: 'kpi-tiles',
id: 'statisticsBoxes',
height: 100,
tpl: [
'<div class="kpi-meta">',
'<tpl for=".">',
'<span>',
'<div class="statsDiv">{statistic}</div> {description}',
'</span>',
'</tpl>',
'</div>'
],
data: [{
description: Ext.getStore('statisticsStore').getAt(0).data.statistic,
statistic: Ext.getStore('viewStore').getAt(0).data.statistic
},{
description: Ext.getStore('viewStore').getAt(1).data.description,
statistic: Ext.getStore('viewStore').getAt(1).data.statistic
}],
But when I am changing the data for the template so it will load data from the Statistics store, the following error occurs in the console.log: Uncaught TypeError: Cannot read property 'getAt' of undefined.
Data config:
data: [{
description: 'the description',
statistic: Ext.getStore('statisticsStore').getAt(0).data.statistic
}],
Statistics store:
Ext.define('ExecDashboard.store.Statistics', {
extend: 'Ext.data.Store',
alias: 'store.statistics',
storeId: 'statisticsStore',
model: 'ExecDashboard.model.Statistics',
proxy: {
type: 'ajax',
url: '/statistics',
reader: 'json'
}
});
Produces the following JSON:
[{"statistic":"1"}, {"statistic":"2"}]
The store is loaded in the viewModel:
stores: {
Statistics: {
type: 'statistics',
autoLoad: true
}
}
I think the problem is that the store is not loaded at that moment. But I don't know how to solve this problem. I know that 'Ext.getStore('statisticsStore').getAt(0).data.statistic' works in the console.log when the store is loaded.
Use an Ext.view.View, that's exactly what the class is for:
xtype: 'dataview',
cls: 'kpi-tiles kpi-meta',
id: 'statisticsBoxes',
height: 100,
itemSelector: '.statsDiv',
tpl: [
'<tpl for=".">',
'<span>',
'<div class="statsDiv">{statistic}</div> {description}',
'</span>'
'</tpl>'
],
store: 'statisticsStore'
You probably need to set autoLoad: true on your store.
An event listener on the store in my viewModel solves the problem.
Statistics: {
type: 'statistics',
autoLoad: true,
listeners: {
load: function(){
var data = [{"description": "New", "statistic" : this.data.items[0].data.statistic}];
Ext.getCmp('statisticsBoxes').update(data);
}
}
}
When the store is loaded, the event will be fired which updates the Xtemplate with new data

Not Able to load data into a listview from store in Sencha touch

I am a beginner in sencha programming trying to build an app that takes in data from a remote server and displays it as a list in my app. I am trying to load data from a JSON store into a listview. My Store Code is:
Ext.define('RestaurantGlobal.store.CategoryColumnsStore', {
extend: 'Ext.data.Store',
requires: [
'RestaurantGlobal.model.CategoryColumns'
],
config: {
model: 'RestaurantGlobal.model.CategoryColumns',
storeId: 'CategoryColumnsStore',
proxy: {
type: 'ajax',
url: 'http://eatpunjab.gramapp.in/Data/?Model=Category&All=True',
reader: {
type: 'json',
rootProperty: 'fields'
},
autoLoad: true
}
}
});
My Model Code is:
Ext.define('RestaurantGlobal.model.CategoryColumns', {
extend: 'Ext.data.Model',
uses: [
'RestaurantGlobal.model.BaseModelColumns'
],
config: {
fields: [
{
name: 'Name',
type: 'string'
},
{
name: 'Image',
type: 'string'
}
],
}
});
and my view code is:
var categorystore = Ext.create("RestaurantGlobal.store.CategoryColumnsStore");
Ext.define('RestaurantGlobal.view.CategoriesPage', {
extend: 'Ext.Panel',
config: {
styleHtmlCls: 'maincontainer',
styleHtmlContent: true,
layout: {
type: 'vbox'
},
items: [
{
xtype: 'titlebar',
flex: 0.5,
docked: 'top',
title: 'Menu'
},
{
xtype: 'list',
flex: 4,
cls:'customcontainer',
margin: '0 10 0 10',
itemTpl: [
'<img src="http://eatpunjab.gramapp.in/media/{Image}" width="40" height="40"/><h2>{Name}</h2>'
],
scrollToTopOnRefresh: false,
store: categorystore
},
]
}
});
When I open the app in my browser, I get a blank listview.
What is missing in my code that is causing the data to not be loaded into the listview?
autoLoad is a config option for the store, but you've put it in the proxy.

Sencha touch Loading mask when rest request process

is it possible to make a loading bar , when my list need to get json result from my web service?
Here is my code
list.js
Ext.define('bluebutton.view.BlueButton.MemberList', {
extend: 'Ext.List',
xtype: 'memberlistcard',
requires: [
'Ext.field.Select',
'Ext.field.Search',
'bluebutton.view.BlueButton.MemberDetail',
'Ext.plugin.ListPaging',
'Ext.plugin.PullRefresh',
'Ext.dataview.Override'
],
config: {
styleHtmlContent: true,
scrollable: 'vertical',
itemHeight :20,
variableHeights : false,
store : { xclass : 'bluebutton.store.BlueButton.MemberList'},
grouped: true,
indexBar: true,
// plugins: [
//
// {
// xclass: 'Ext.plugin.ListPaging',
// autoPaging: true
//
// }
// ],
id :'memberlist',
items: [
],
emptyText: '<p class="no-search-results">No member record found matching that search</p>',
itemTpl: Ext.create(
'Ext.XTemplate',
'<div class="tweet-wrapper">',
'<table>',
'<tr>',
'<td rowspan="2" width="28%" >',
// '<div style="padding-left: 30px;">',
// ' <img src="{imgUrl}" width="140" height="130" /></div>',
'</td>',
'<td>',
' <div class="tweet">',
' <h3>{consumer_bbID}</h3>',
' <h3>Name: {fullName}</h3>',
' <h3>Point Avalaible : {currentPoint} , Last Visited : {lastVisited}</h3>',
' </div>',
'</td>',
'</tr>',
'</table>',
'</div>'
),
},
});
Store.js
Ext.define('bluebutton.store.BlueButton.MemberList', {
extend: 'Ext.data.Store',
requires: [
'bluebutton.model.BlueButton.MemberList'
],
config: {
grouper: {
groupFn: function (record) {
return record.get('fullName')[0];
}
},
model :'bluebutton.model.BlueButton.MemberList',
storeId :'memberStore',
autoLoad: true,
clearOnPageLoad: false, // This is true by default
pageSize: 10,
}
});
model.js
Ext.define('bluebutton.model.BlueButton.MemberList', {
extend: 'Ext.data.Model',
config: {
idProperty: 'memberlistModel',
fields: [
{ name :'memberId'},
{ name: 'fullName' },
{ name: 'phone' },
{ name: 'age' },
{ name: 'point' },
{ name :'address'},
{ name: 'emailAddress' },
{ name: 'lastVisited' },
{ name: 'consumer_bbID' },
{ name: 'merchant_bbID' },
{ name: 'sessionId' },
{ name: 'deviceId' },
{ name: 'currentPoint' },
],
proxy: {
type: 'rest',
url: 'http://192.168.251.131:8080/WebCommon/rest/BBWebService/getMembersList',
reader: 'json',
actionMethods: {
create: 'POST',
read: 'GET',
update: 'PUT',
destroy: 'DELETE'
},
noCache: false, // get rid of the '_dc' url parameter
extraParams: {
sessionId: "1",
deviceId: "1",
merchant_bbID: "merchant1",
// add as many as you need
},
reader: {
type: 'json',
rootProperty: 'membersList'
},
writer: {
type: 'json',
},
}
}
});
It may delay few second when sencha load json data from web service? is it possible to implement loading bar when rest getting request from webs ervice