PDA

View Full Version : How to load TreePanel nodes from DB



hermann.s
8 Oct 2014, 4:36 AM
Greetings,

I have the following model/store/tree.
I want to grab some data from the server and add them as tree nodes to the panel.
The following code does not work.

model

Ext.define('EMS.model.Event', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int', mapping: 'Event_ID' },
{ name: 'text', type: 'string', mapping: 'Event_Name' },
{ name: 'leaf', defaultValue: true },
{ name: 'Start_Date', type: 'date' },
{ name: 'End_Date', type: 'date' },
{ name: 'Country_ID' },
{ name: 'Country_Name_EN' },
{ name: 'Participants', type: 'int' },
{ name: 'CO_NR', type: 'int' },
{ name: 'Division' },
{ name: 'Expenses', type: 'float' },
{ name: 'Person_In_Charge' },
{ name: 'Status' },
{ name: 'Organisation_Fee', type: 'float'},
{ name: 'Support_Fee', type: 'float' }
]
});

store

Ext.define('EMS.store.application.SidePanel', {
extend: 'Ext.data.TreeStore',
model: 'EMS.model.Event',
autoLoad: true,


root: {
text: 'Events',
expanded: true
},


proxy: {
type: 'ajax',
url: EMS.Core.servicePath + 'event',
reader: {
type: 'json'
}
}
});



Ext.define('EMS.view.application.SidePanel', {


extend: 'Ext.tree.Panel',
alias: 'widget.application.SidePanel',


itemId: 'sidePanel',
title: EMS.Core.translate('MENU_TITLE'),
animate: false,
animCollapse: 250,
autoScroll: true,
collapseDirection: 'left',
collapseMode: 'mini',
collapsible: true,
frame: false,
lines: false,
region: 'west',
rootVisible: false,
useArrows: true,


hideMode: 'display',

width: 200,
store: 'application.SidePanel',


header: false
}


server response

[{"Event_ID":132,"Event_Name":"Wacken Open Air 2015","Portal_ID":"johndoe","Is_Deleted":false,"Start_Date":"2015-03-20T00:00:00","End_Date":"2015-03-23T00:00:00","Country_ID":86,"Status":"Active","Event_Data_ID":131,"Participants":39,"CO_NR":26013020,"Division":"Event Management","Expenses":22.0,"Person_In_Charge":"John Doe","Organisation_Fee":30.0,"Support_Fee":50.0,"Country_Name_EN":"Germany","Country_Name_DE":"Deutschland"}]

slemmon
14 Oct 2014, 2:30 AM
Hi,

You've set the leaf field to have a default value of true, but your root node is not a leaf so you'll need to set it to leaf: false

bp5