PDA

View Full Version : Problem with multiple JsonReader



CyberLine
6 Aug 2009, 12:00 AM
Hi there.

i have a new Problem with Ext.

I have 2 grid Panels at one page, both with exactly config except the storedata.

so i have the grid[0]:


grid[0] = new Ext.grid.GridPanel({
loadMask: true,
store: store[0],
frame: false,
autoHeight: true,
autoWidth: true,
collapsible: true,
animCollapse: true,
iconCls: 'icon-grid',
autoExpandColumn: 'title',
columns: [{
id: 'id',
header: "TicketID",
width: 100,
sortable: true,
dataIndex: 'id',
groupable: false
},{
id: 'kdnummer',
hidden: true,
header: "Kundennummer",
width: 100,
sortable: true,
dataIndex: 'kundennummer'
},{
id: 'title',
header: "Titel",
//width: 350,
sortable: true,
dataIndex: 'kurztitel',
groupable: false
},{
header: "Flag",
width: 50,
sortable: false,
dataIndex: 'flag',
renderer: renderTicketFlags
},{
id: 'prio',
header: "Prio",
hidden: true,
sortable: true,
dataIndex: 'prio'
}],

view: new Ext.grid.GroupingView({
//forceFit: true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Tickets" : "Ticket"]})'
}),

bbar: toolbar[0]
});the store[0]:

store[0] = new Ext.data.GroupingStore({
storeId: 'store_0',
autoDestroy: true,
reader: reader[0],
autoLoad: {
params: {
start: 0,
limit: 15
}
},
url: 'responder.php',
sortInfo: {
field: 'id',
direction: "ASC"
},
groupField: 'prio'
});the reader[0]:

reader[0] = new Ext.data.JsonReader({
root: 'tickets_0',
totalProperty: 'ticketCount',
fields: [
{name: 'id', type: 'float'},
{name: 'kurztitel'},
{name: 'time1'},
{name: 'time2'},
{name: 'kundennummer', type: 'float'},
{name: 'bla', type: 'float'},
{name: 'prio', type: 'float'},
{name: 'process'},
{name: 'flag', type: 'float'}
]
});works fine ... but now when i try to "clone" with:

reader[1] = new Ext.data.JsonReader({
root: 'tickets_3',
totalProperty: 'ticketCount',
fields: [
{name: 'id', type: 'float'},
{name: 'kurztitel'},
{name: 'time1'},
{name: 'time2'},
{name: 'kundennummer', type: 'float'},
{name: 'bla', type: 'float'},
{name: 'prio', type: 'float'},
{name: 'process'},
{name: 'flag', type: 'float'}
]
});

store[1] = new Ext.data.GroupingStore({
storeId: 'store_1',
autoDestroy: true,
reader: reader[1],
autoLoad: {
params: {
queue: 3,
start: 0,
limit: 15
}
},
url: 'responder.php',
sortInfo: {
field: 'id',
direction: "ASC"
},
groupField: 'prio'
});

grid[1] = grid[0].cloneConfig({store:store[1],bbar:toolbar[1]});
i get the following error and only grid[1] is filled up with data:



reader is null
doRequest()("read", null, Object start=0 limit=15, null, function(), Object baseParams=Object removed=[0] storeId=store_0, Object params=Object)ext-all-debug.js (Linie 32914)
request()("read", null, Object start=0 limit=15, null, function(), Object baseParams=Object removed=[0] storeId=store_0, Object params=Object)ext-all-debug.js (Linie 32408)
execute()("read", null, Object params=Object)ext-all-debug.js (Linie 30838)
load()(Object params=Object)ext-all-debug.js (Linie 30724)
apply()()ext-base.js (Linie 7)

if (typeof(params[reader.meta.root]) === 'object') {

is there no way to use more than one reader in a script ?
It also doesn't work when using reader[0] again in store[1].

Condor
6 Aug 2009, 12:08 AM
The clone of grid[0] will use the same GroupingView instance (which isn't allowed).

Haven't tried, but this probably works:

grid[1] = grid[0].cloneConfig({
store:store[1],
bbar:toolbar[1],
view:new Ext.grid.GroupingView(grid[0].getView().initialConfig)
});

CyberLine
6 Aug 2009, 12:32 AM
Ok, thanks, that worked fine.

But now the toolbar has some mystific "features":


toolbar[0] = new Ext.PagingToolbar({
pageSize: 15,
store: store[0]
});
toolbar[1] = toolbar[0].cloneConfig({store:store[1]});


grid[0] has 15 rows, grid[1] 16. toolbar[0] has no data, toolbar[1] shows 16 and page 1 of 2.
When i click Page 2 in toolbar[1], the grid reloads with the data from grid[0] ?

Store definitions:


store[0] = new Ext.data.GroupingStore({
storeId: 'store_0',
autoDestroy: true,
reader: reader[0],
autoLoad: {
params: {
start: 0,
limit: 15
}
},
url: 'responder.php',
sortInfo: {
field: 'id',
direction: "ASC"
},
groupField: 'prio'
});

store[1] = new Ext.data.GroupingStore({
storeId: 'store_1',
autoDestroy: true,
reader: reader[1],
autoLoad: {
params: {
queue: 3,
start: 0,
limit: 15
}
},
url: 'responder.php',
sortInfo: {
field: 'id',
direction: "ASC"
},
groupField: 'prio'
});

when click reload or next page in toolbar[1], queue param is missing in post request. Another view problem ?

Condor
6 Aug 2009, 12:43 AM
cloneConfig is unreliable (because some constructors modify the initialConfig).

I would switch to using factory methods:

var createReader = function(config){
return new Ext.data.JsonReader(Ext.apply({
totalProperty: 'ticketCount',
fields: [
{name: 'id', type: 'float'},
{name: 'kurztitel'},
{name: 'time1'},
{name: 'time2'},
{name: 'kundennummer', type: 'float'},
{name: 'bla', type: 'float'},
{name: 'prio', type: 'float'},
{name: 'process'},
{name: 'flag', type: 'float'}
]
}, config));
},
createStore = function(config){
return new Ext.data.GroupingStore(Ext.apply({
autoDestroy: true,
autoLoad: {
params: {
start: 0,
limit: 15
}
},
url: 'responder.php',
sortInfo: {
field: 'id',
direction: "ASC"
},
groupField: 'prio'
}, config));
},
createToolbar = function(config){
return new Ext.PagingToolbar(Ext.apply({
pageSize: 15
}, config));
},
createGrid = function(config){
return new Ext.grid.GridPanel(Ext.apply({
loadMask: true,
frame: false,
autoHeight: true,
autoWidth: true,
collapsible: true,
animCollapse: true,
iconCls: 'icon-grid',
autoExpandColumn: 'title',
columns: [{
id: 'id',
header: "TicketID",
width: 100,
sortable: true,
dataIndex: 'id',
groupable: false
},{
id: 'kdnummer',
hidden: true,
header: "Kundennummer",
width: 100,
sortable: true,
dataIndex: 'kundennummer'
},{
id: 'title',
header: "Titel",
sortable: true,
dataIndex: 'kurztitel',
groupable: false
},{
header: "Flag",
width: 50,
sortable: false,
dataIndex: 'flag',
renderer: renderTicketFlags
},{
id: 'prio',
header: "Prio",
hidden: true,
sortable: true,
dataIndex: 'prio'
}],
view: new Ext.grid.GroupingView({
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Tickets" : "Ticket"]})'
})
}, config));
},
reader = [
createReader({
root: 'tickets_0'
}),
createReader({
root: 'tickets_3'
})
],
store = [
createStore({
reader: reader[0],
storeId: 'store_0'
}),
createStore({
reader: reader[1],
storeId: 'store_1'
})
],
toolbar = [
createToolbar({
store: store[0]
}),
createToolbar({
store: store[1]
})
],
grid = [
createGrid({
store: store[0],
bbar: toolbar[0]
}),
createGrid({
store: store[1],
bbar: toolbar[1]
})
];

CyberLine
6 Aug 2009, 12:59 AM
YES!. Everything is fine now.

Big thanks, made my Day :)