Sencha Touch 2.3..1 DataView is not loading Store details loaded later - dataview

I want to show some details on to Sencha Touch 2.3.1 DataView.
Actual Data to be loaded will come later to the DataView object creation.
I am not using Store proxy, but I have my own existing HTTP Request API for getting the JSON data. So once I get the data, I am creating a DataModel and adding to Store.
When I debug the code, I see it is adding and Store is populated with Data.
Now I am getting the DataView object with Ext.getCmp("") and setting the Store.
When I see the DataView object, I see the store (_store) containing the data (_data) in it.
But still the DataView is not populated with the datails.
Please help me in this context
My DataModel:
Ext.define('AlbumsListDM', {
extend: 'Ext.data.Model',
config: {
fields: [
"user",
"title",
"subtitle",
"image"
]
}
});
My Store:
Ext.define('AlbumsListStore', {
extend: 'Ext.data.Store',
config: {
model: 'AlbumsListDM',
autoLoad: true
}
});
My DataView:
Ext.define(APP_NAME+'.view.AlbumsList', {
extend: 'Ext.DataView',
id: 'viewAlbumsListID',
requires: ['AlbumsListDM'],
config: {
width:'100%',
height:'100%',
layout: 'fit',
items: [{
xtype: 'dataview',
scrollable: true,
inline: true,
cls: 'dataview-inline',
itemTpl: new Ext.XTemplate('<div class="img" style="background-image: url({image});">{title}</div>')
}]
}
});
My Construction of store and updating DataView:
Ext.create('AlbumsListStore', { id: 'AlbumsListStoreID' });
var albumsList = myJsonData;
var albumsListStore = Ext.getStore('AlbumsListStoreID');
var count = albumsList.length;
for(var index = 0; index < count; index++) {
albumsListStore.add(Ext.create('AlbumsListDM', albumsList[index]));
}
var viewAlbumsList = Ext.getCmp("viewAlbumsListID");
viewAlbumsList.setStore(albumsListStore);
Thanks
Siva

Related

Displaying the number of rows in a grid - Extjs

So I'm trying to display the number of rows (records) returned from a grid. Here's the code:
Ext.define('AM.view.user.List' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: '<center>Data Management</center>',
store: 'Users',
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [
{ xtype: 'tbtext', text: 'Number of Records\:' + ***code that will return number of records*** },
{ xtype: 'tbfill' },
{ text: 'Print' },
{ text: 'Export' }
]
}],
...
I'm not sure how to use the getCount() method to return the number of rows from this grid (or store?). Any ideas?
Heres: my store:
Ext.define('AM.store.Users', {
extend: 'Ext.data.Store',
model: 'AM.model.User',
fields: ['field1', 'field2', 'field3'],
data: [
{field1: 'Data 1', field2: 'Data 2', field3: 'Data 3'},
{field1: 'Data 1', field2: 'Data 2', field3: 'Data 3'},
{field1: 'Data 1', field2: 'Data 2', field3: 'Data 3'}
]
});
You won't be able to do this dynamically, where it updates on its own, so you will have to use a placeholder and update the panel when the store is loaded.
{ xtype: 'tbtext', itemId: 'numRecords' }
Then:
listeners: {
render: function(store) {
store.on('load', function(records) {
var count = records.length; //or store.getTotalCount(), if that's what you want
grid.down('#numRecords').setText('Number of Records: ' + count);
});
}
}
You can try to add a paging toolbar and use the properties displayInfo & displayMsg.
Try this code :
bbar : {
xtype : 'pagingtoolbar',
displayInfo: true,
store:'your store',
displayMsg : 'Total rows {2}'// defaultvalue = 'Displaying {0} - {1} of {2}'
}
Assuming your store is loaded before the grid is rendered, this will probably work:
Ext.data.StoreManager.lookup("Users").getCount();
If the store loads dynamically, you will need to attach an event to the store's load event to update your grid, comment if the above code does not work and I can probably help you.
As it has already been said, you have to wait for the store to be loaded before using getCount. Except in the case you'd really use a memory store like the one in your example, but I doubt you'd want to display a dynamic number of record for that use case...
So, you have to listen for the load event of the store and update your text item then. The load event will fire each time the store is loaded, reloaded, etc., which may occur multiple times if your grid is paged or allow for filtering, etc. That means that our number of records will be kept in sync with the actual content of the store. Good.
Now, how to install that listener? One very common place for putting that kind of treatment is in the initComponent method of your component.
Here's the code. See the comments for a crash course in overriding initComponent (see another answer for a lecture on the topic).
Ext.define('AM.view.user.List' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: '<center>ECRIS-MetaData Management</center>',
store: 'Users',
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [
// Give an itemId to this component to make it easy to
// reference later.
{ xtype: 'tbtext', text: 'Loading...', itemId: 'recordNumberItem' },
{ xtype: 'tbfill' },
{ text: 'Print' },
{ text: 'Export' }
]
}],
initComponent: function() {
// We're overriding an existing method, so that's very important to call
// the parent method, or the component will break in awful sufferings
this.callParent(arguments);
// I'm putting the code *after* callParent, so that the store is available
var store = this.getStore(),
// Using ComponentQuery to retrieve the text item
textItem = this.down('#recordNumberItem');
// Using `mon` instead of `on` for better memory management (the listener
// will be removed from the store automatically when the component is
// destroyed).
this.mon(store, 'load', function() {
// We're left with the easy part...
textItem.setText("Number of records: " + store.getCount());
});
}
// ...
});

Sencha Touch list store disable sorting

I have my list which is getting data from php service, the data received is in the order I need. But sencha automatically sort my list alphabetically.
Below is my code:
Ext.define('MyList', {
extend: 'Ext.dataview.List',
config: {
grouped: true,
plugins: [
{
xclass: 'Ext.plugin.PullRefresh',
pullRefreshText: 'Pull down to refresh'
},
{
xclass: 'Ext.plugin.ListPaging',
autoPaging: true,
noMoreRecordsText: 'No More Records'
}
]
},
initialize: function () {
this.callParent(arguments);
var store = Ext.create('Ext.data.Store', {
pageParam: 'page',
grouper: {
groupFn: function (record) {
return record.data.group_label;
}
},
model: 'ListItem',
proxy: {
type: 'ajax',
url: '/m/services/activity_list_items.php',
reader: {
type: 'json',
rootProperty: 'root.results'
}
}
});
var template = Ext.create('GenericListItem', {
hascounts: true,
hasicon: true,
varmap: {
descr: 'subtext',
count: 'sub_item_cnt',
itemid: 'itemid',
uniqid: 'uniqid'
}
});
var emptyText = 'Recent Activity Items';
this.setStore(store);
this.setItemTpl(template);
this.setEmptyText(emptyText);
}
});
How can I avoid the auto sorting of list?
Add the following to your store config.
remoteSort : true,
remoteSort defaults to false in sencha. So sencha automatically sorts in the client side. Check the link for more details http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Store-cfg-remoteSort
Just remove this:
grouped: true
from your list config if you don't want a header for each item and compulsory to remove this:
grouper: {
groupFn: function (record) {
return record.data.group_label;
}
}
from your store because basically in your situation grouper property are using for grouping your item alphabetically based on your group_label field. Hope it helps :)

Sencha add dynamically tap listener to record list

I have an Ext.data.Store and a Ext.Panel with a list.
I add record dynamically with this command:
myStore.add({txt: r});
I would like to add a listener that when I click on a list record, it shows me the record data in a message box.
How can I do it?
Ext.data.store
var myStore = Ext.create('Ext.data.Store', {
storeId: 'MyStore',
fields: ['txt']
}); // create()
Ext.Panel
listpanel = new Ext.Panel({
layout: 'fit', // important to make layout as 'fit'
items: [
{
xtype: 'titlebar',
id: 'myTitle',
docked: 'top',
title: 'Before Change title'
},
{
//Definition of the list
xtype: 'list',
itemTpl: '{txt}',
store: myStore,
}]
});
You need to use itemtap event of the Ext.List component.
E.g
....
....
xtype: 'list',
itemTpl: '{txt}',
store: myStore,
listeners : {
itemtap : function(item, num, record, ev) {
var myTxt = item.getStore().getAt(num).get('txt');
Ext.Msg.alert('Message','Tapped record : '+myTxt);
}
}
....
....

Can the Knockout Concurrency plugin track newly added or deleted rows?

I'm trying to use the Knockout Concurrency plugin in my project, and I'm currently fiddling with the example code, but I'm not getting it to work:
https://github.com/AndersMalmgren/Knockout.Concurrency/wiki/Getting-started
ViewModel = function() {
this.name = ko.observable("John").extend({ concurrency: true});
this.children = [{ name: ko.observable("Jane").extend({concurrency: true })}, { name: ko.observable("Bruce").extend({concurrency: true })}];
this.getData = function() {
//Simulate backend data
var data = { name: "John Doe", children: [{ name: "Jane Doe"},{ name: "Bruce Wayne"}, { name: "New row"}]};
new ko.concurrency.Runner().run(this, data);
}
}
ko.applyBindings(new ViewModel());
http://jsfiddle.net/rCVk4/3/
Nothing happens and the newly added item is not tracked by the plugin, does anyone know why?
Thanks for trying out my Plugin, really fast too, I uploaded the code today!
The plugin does indeed support tracking of deleted and added rows. But for it to know which rows are what It needs you to supply it with a mapper
var mappings = {
children: {
key: function(item) {
return ko.utils.unwrapObservable(item.id);
},
create: function(data) {
return { id: data.id, name: data.name };
}
}
};
The name children corresponds to the name of the array.
The Key method is used to identify the property used as an identifier.
The Create method is used to create new rows (Added rows).
You can download the MVC3 sample from Github for a fully featured Demo, also please try out this Fiddle
http://jsfiddle.net/7atZT/

List pushed in navigation view is not rendered

I am using sencha touch 2.
My App.js file (summed up)
Ext.application({
launch: function() {
// ...
var list = Ext.create('Ext.List', {
itemTpl : '<img src="{icon}"/>{title}<br/>{description}',
store: store,
listeners: {
select: function(view, record) {
var customView = Ext.create(record.get('view'));
navView.push(customView);
view.deselectAll();
}
}
});
//----------------------------------------------------------------------
var navView = Ext.create('Ext.NavigationView', {
navigationBar:{
items: [{
text:'refresh',
align: 'right'
}]
},
items: [list]
});
//----------------------------------------------------------------------
Ext.Viewport.add(navView);
}
});
When i am loading a view within my navigation view, everything is ok appart when it conains a list.
There is a view with a list in it.
The subpanel is rendered, but not the list view (the list view has been tested and is of course rendering in a different context)
Ext.define('ts.views.jobs', {
extend: 'Ext.Panel',
layout:'fit',
config:{
title:'Jobs'
},
initialize: function() {
this.callParent();
var jobsStore = Ext.create('Ext.data.Store', {
model: 'ts.model.job',
data: [{
key2: 'key1'
}, {
key2:'key2'
},
{
key2:'key3'
}
]
});
var jobsList = Ext.create('Ext.List', {
xtype: 'jobsList',
ui: 'round',
itemTpl : 'ok{key}',
store: jobsStore
});
var panel = Ext.create('Ext.Panel', {
html: 'Testing'
});
this.add([jobsList,panel]);
}
});
What am i doing wrong ?
* is it a navigationview bug ?
* am i not initializing properly in my subview ?
Thx for your help.
This was cross posted to the sencha touch forums: http://www.sencha.com/forum/showthread.php?184492-List-pushed-in-navigation-view-is-not-rendered and the answer accepted was:
layout config needs to be within the config object.