radtad
17 Apr 2012, 5:13 PM
I'm trying to load in a complex nested structure with a paging store. I noticed another thread where something similar was done, but can't seem to get a totalProperty count on the paging toolbar. The data returns just fine in the view.
http://www.sencha.com/forum/showthread.php?144855-load-nested-rows-in-model&highlight=nested+data+store+load (http://www.sencha.com/forum/showthread.php?144855-load-nested-rows-in-model&highlight=nested+data+store+load)
Note: I can't change the the JSON data coming back in as it isn't mine.
Ext.define('RH.model.mrln.PagedThumbnails', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{name:'id', type:'integer', mapping: 'id'},
{name:'mediatype', type:'string', mapping: 'mediatype'},
{name:'size', type:'integer', mapping: 'size'},
{name:'name', type:'string', mapping: 'name'},
{name:'job', type:'string', mapping: 'job'},
{name:'description', type:'string', mapping: 'description'},
{name:'visible', type:'boolean', mapping: 'visible', defaultValue: true},
{name:'format', type:'string', mapping: 'format'},
{name:'length', type:'string', mapping: 'length'},
{name:'owner', type:'string', mapping: 'owner'},
{name:'uploaddt', type:'date', mapping: 'uploaddate', dateFormat: 'U', convert: function(v,record) {return Ext.isString(v) ? v : v.time;} },
{name:'contenttype', type:'string', mapping: 'contenttype'},
{name:'leaf', type:'boolean', defaultValue: true},
{name:'isdir', type:'boolean', defaultValue: false},
{name:'parentdir_id', type: 'integer', mapping: 'parentdir_id'},
{name: 'online', type: 'boolean', defaultValue: false}
]
});
Ext.define('RH.store.mrln.PagedThumbnails', {
extend: 'Ext.data.Store',
model: 'RH.model.mrln.PagedThumbnails',
remoteSort: false,
proxy: {
actionMethods: { read: 'POST'},
headers: {'Content-Type': 'application/json; charset=utf-8' },
type: 'ajax',
noCache: false,
url: 'data.json',
reader: {
type: 'json',
root: 'contents',
totalProperty: 'count',
extractData: function(root) {
var data = root[0].contents;
return Ext.data.reader.Reader.prototype.extractData.call(this, [data]);
}
}
}
});
var me = this;
var store = Ext.create('RH.store.mrln.PagedThumbnails');
store.load({
params: {
method: 'getList'
}
});
{
xtype: 'pagingtoolbar',
store: 'RH.store.mrln.PagedThumbnails',
dock: 'bottom',
displayInfo: true
}
[
{
"pid": 3437,
"count": 8,
"contents": [
{"id": 1501111,"mediatype": "jpg","size": 195387,"name": "Test","description": "types: jpg","format": "","length": 0,"owner": "trubenda","uploaddate": {"time": 1326931109},"contenttype": "media","job": "test","visible": true,"online": true}
]
}
]
http://www.sencha.com/forum/showthread.php?144855-load-nested-rows-in-model&highlight=nested+data+store+load (http://www.sencha.com/forum/showthread.php?144855-load-nested-rows-in-model&highlight=nested+data+store+load)
Note: I can't change the the JSON data coming back in as it isn't mine.
Ext.define('RH.model.mrln.PagedThumbnails', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{name:'id', type:'integer', mapping: 'id'},
{name:'mediatype', type:'string', mapping: 'mediatype'},
{name:'size', type:'integer', mapping: 'size'},
{name:'name', type:'string', mapping: 'name'},
{name:'job', type:'string', mapping: 'job'},
{name:'description', type:'string', mapping: 'description'},
{name:'visible', type:'boolean', mapping: 'visible', defaultValue: true},
{name:'format', type:'string', mapping: 'format'},
{name:'length', type:'string', mapping: 'length'},
{name:'owner', type:'string', mapping: 'owner'},
{name:'uploaddt', type:'date', mapping: 'uploaddate', dateFormat: 'U', convert: function(v,record) {return Ext.isString(v) ? v : v.time;} },
{name:'contenttype', type:'string', mapping: 'contenttype'},
{name:'leaf', type:'boolean', defaultValue: true},
{name:'isdir', type:'boolean', defaultValue: false},
{name:'parentdir_id', type: 'integer', mapping: 'parentdir_id'},
{name: 'online', type: 'boolean', defaultValue: false}
]
});
Ext.define('RH.store.mrln.PagedThumbnails', {
extend: 'Ext.data.Store',
model: 'RH.model.mrln.PagedThumbnails',
remoteSort: false,
proxy: {
actionMethods: { read: 'POST'},
headers: {'Content-Type': 'application/json; charset=utf-8' },
type: 'ajax',
noCache: false,
url: 'data.json',
reader: {
type: 'json',
root: 'contents',
totalProperty: 'count',
extractData: function(root) {
var data = root[0].contents;
return Ext.data.reader.Reader.prototype.extractData.call(this, [data]);
}
}
}
});
var me = this;
var store = Ext.create('RH.store.mrln.PagedThumbnails');
store.load({
params: {
method: 'getList'
}
});
{
xtype: 'pagingtoolbar',
store: 'RH.store.mrln.PagedThumbnails',
dock: 'bottom',
displayInfo: true
}
[
{
"pid": 3437,
"count": 8,
"contents": [
{"id": 1501111,"mediatype": "jpg","size": 195387,"name": "Test","description": "types: jpg","format": "","length": 0,"owner": "trubenda","uploaddate": {"time": 1326931109},"contenttype": "media","job": "test","visible": true,"online": true}
]
}
]