PDA

View Full Version : Data store troubles



toxkillfraex
10 Apr 2012, 12:28 AM
It's probably a retarded mistake, but I'm at the point of tearing my hair out. So I'll ask anyway.

I have a grid defined like this

var grid = new Ext.grid.GridPanel
({
id: 'auditGrid',

store : null,

columns: [

{ header: 'Timestamp', dataIndex: 'timestamp', width: 70 },
{ header: 'Reason', dataIndex: 'reason' , flex:1},
{ header: 'Action', dataIndex: 'action' ,width:95},
{ header: 'User id', dataIndex: 'userid', width:95},
{ header: 'First name', dataIndex: 'firstname', width:130},
{ header: 'Family name', dataIndex: 'familyname', width:130}


],

viewConfig:
{
forceFit: true
},

autoScroll: true,
columnLines: true
});


I have a model defined like this:


Ext.define('APP.model.AuditTrail',
{
extend: 'Ext.data.Model',

fields:
[
'timestamp',
'reason',
'action',
'userid',
'firstname',
'familyname'
]
});


and in a controller I try to create the store with the model. If I load the store there it returns all the records fine, but just setting the store of the grid gives me 5 empty lines...

var auditStore = Ext.create('Ext.data.Store',
{
model : 'APP.model.AuditTrail',

proxy:
{
type : 'rest',
url : APP.model.Cookie.config.serverUrl + '/app/documents/'
+ document.data.id + '/audits',

reader :
{
type : 'json',
root : 'content.audittrail'
},

actionMethods :
{
read : 'GET'
},

extraParams :
{
sessionId : session.sessionId
},

autoLoad : true
}
});

me.getAuditGrid().store = auditStore;

/*auditStore.load(function(record, operation, success)
{
console.log(record);



});*/

I try the url that's used and it returns json that kinda looks like this:



{"content":{"audittrail":[{"timestamp":1334041821000,"reason":null,"action":"dm_getfile","userid":1,"firstname":"Gordon","familyname":"Freeman"},{"timestamp":1334041820000,"reason":null,"action":"dm_fetch","userid":1,"firstname":"Gordon","familyname":"Freeman"},{"timestamp":1334009763000,"reason":null,"action":"dm_getfile","userid":1,"firstname":"Gordon","familyname":"Freeman"},{"timestamp":1323259972000,"reason":null,"action":"dm_link","userid":1,"firstname":"Gordon","familyname":"Freeman"}]},"status":{"message":"OK","status":200}

it returns over a thousand records but then I'd more expect a lengthy load time instead of just... blank recods in the grid =/

what am i doing wrong?
I tried reconfigure on the store but then it simply gives me an error in the trend of not finding length of undefined

vietits
10 Apr 2012, 12:54 AM
autoLoad is a store config, not proxy config.


var auditStore = Ext.create('Ext.data.Store',{
model: 'APP.model.AuditTrail',
proxy: {
type : 'rest',
url : APP.model.Cookie.config.serverUrl + '/app/documents/' + document.data.id + '/audits',
reader : {
type : 'json',
root : 'content.audittrail'
},
actionMethods : {
read : 'GET'
},
extraParams: {
sessionId : session.sessionId
},
// autoLoad : true
},
autoLoad: true
});

toxkillfraex
10 Apr 2012, 12:58 AM
autoLoad is a store config, not proxy config.


var auditStore = Ext.create('Ext.data.Store',{
model: 'APP.model.AuditTrail',
proxy: {
type : 'rest',
url : APP.model.Cookie.config.serverUrl + '/app/documents/' + document.data.id + '/audits',
reader : {
type : 'json',
root : 'content.audittrail'
},
actionMethods : {
read : 'GET'
},
extraParams: {
sessionId : session.sessionId
},
// autoLoad : true
},
autoLoad: true
});




oh that didn't fix it, but now my server console is showing it's being loaded
so that's one step forward definitely

I'm still just stuck with 5 empty record lines ;_____;

vietits
10 Apr 2012, 1:10 AM
You should use reconfigure to assign new store for the grid:


// me.getAuditGrid().store = auditStore;
me.getAuditGrid().reconfigure(auditStore);

toxkillfraex
10 Apr 2012, 1:15 AM
You should use reconfigure to assign new store for the grid:


// me.getAuditGrid().store = auditStore;
me.getAuditGrid().reconfigure(auditStore);


the console happily crashes on me then




Uncaught TypeError: Cannot read property 'length' of undefined

Ext.define.onLastFocusChangedext-all-debug.js:89284 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.setLastFocusedext-all-debug.js:59431 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.clearSelectionsext-all-debug.js:59543 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.refreshext-all-debug.js:59523 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.bindext-all-debug.js:59143 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.bindStoreext-all-debug.js:60584 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.bindStoreext-all-debug.js:78007 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.reconfigureext-all-debug.js:78033 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.openDocumentAuditAudit.js:80 (https://localhost:8443/EpaClient/app/controller/Audit.js?_dc=1334049420741)
Ext.define.openDocumentViewer.js:77 (https://localhost:8443/EpaClient/app/controller/Viewer.js?_dc=1334049420714)
Ext.define.openDocumentDocumentBrowser.js:372 (https://localhost:8443/EpaClient/app/controller/DocumentBrowser.js?_dc=1334049420736)
fireext-all-debug.js:10658 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.continueFireEventext-all-debug.js:13854 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.fireEventext-all-debug.js:13834 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.override.fireEventext-all-debug.js:24019 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.processUIEventext-all-debug.js:69488 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
Ext.define.handleEventext-all-debug.js:69412 (https://localhost:8443/EpaClient/ext/ext-all-debug.js)
(anonymous function)
wrap





might this be because the window exists but is hidden at the time the function is called?

vietits
10 Apr 2012, 1:29 AM
The following code works well for me on Chrome 18, Ext 4.0.7:


Ext.onReady(function(){
var grid = new Ext.grid.GridPanel({
renderTo: Ext.getBody(),
id: 'auditGrid',
store : null,
columns: [
{ header: 'Timestamp', dataIndex: 'timestamp', width: 70 },
{ header: 'Reason', dataIndex: 'reason' , flex:1},
{ header: 'Action', dataIndex: 'action' ,width:95},
{ header: 'User id', dataIndex: 'userid', width:95},
{ header: 'First name', dataIndex: 'firstname', width:130},
{ header: 'Family name', dataIndex: 'familyname', width:130}
],
viewConfig: {
forceFit: true
},
autoScroll: true,
columnLines: true
});


Ext.define('AuditTrail',{
extend: 'Ext.data.Model',
fields: [
'timestamp',
'reason',
'action',
'userid',
'firstname',
'familyname'
]
});
var auditStore = Ext.create('Ext.data.Store',{
model : 'AuditTrail',
autoLoad : true,
proxy: {
type : 'ajax',
url : 'data.json',
reader : {
type : 'json',
root : 'content.audittrail'
},
actionMethods : {
read : 'GET'
}
}
});


grid.reconfigure(auditStore);
});

data.json


{
"content":{
"audittrail":[{
"timestamp":1334041821000,"reason":null,"action":"dm_getfile","userid":1,"firstname":"Gordon","familyname":"Freeman"
},{
"timestamp":1334041820000,"reason":null,"action":"dm_fetch","userid":1,"firstname":"Gordon","familyname":"Freeman"
},{
"timestamp":1334009763000,"reason":null,"action":"dm_getfile","userid":1,"firstname":"Gordon","familyname":"Freeman"
},{
"timestamp":1323259972000,"reason":null,"action":"dm_link","userid":1,"firstname":"Gordon","familyname":"Freeman"
}]
},
"status":{
"message":"OK","status":200
}
}

toxkillfraex
10 Apr 2012, 1:32 AM
it was indeed because the window was hidden thanks a million your reconfigure definitely did it

and the autoload I did was just plain stupid >.>

THANKS