PDA

View Full Version : not hard coded property fields of Ext.data.XmlReader ?



FOONTIK
25 Nov 2011, 7:29 AM
I have xml

<ROWSET>
<ROW>
<TOTALROWS>4</TOTALROWS>
<KEY>1</KEY>
<ID type="int">1</ID>
<CODE type="string">AS_ADMIN</CODE>
<DESCRIPTION type="string">????????????? AS</DESCRIPTION>
</ROW>
</ROWSET>
I want to get the variable xmlReader by url (or another), but not hard coded. How can I do that?

function xmlFn(){
var xmlReader = "{"+
"name: 'ID',"+
"type: 'int'"+
"}@ {"+
"name: 'CODE',"+
"type: 'string'"+
"}@ {"+
"name: 'DESCRIPTION',"+
"type: 'string'"+
"}";
var xmlReaderArr = xmlReader.split("@");
var xmlReaderArrOut = new Array();;
for (var key in xmlReaderArr) {
var val = xmlReaderArr [key];
xmlReaderArrOut[key] = Ext.util.JSON.decode(val);
}
return xmlReaderArrOut;
};
grid = new Ext.app.ux.FormEditGrid2({
id: 'grid_filter',
store: new Ext.data.Store({
id: 'store_objecttype',
url: 'data/role_table.xml',
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
record: 'ROW',
id: 'KEY',
totalProperty: "TOTALROWS",
fields: xmlFn()//xmlReaderArrOut
})
}),
columns: [{
header: "Id",
dataIndex: 'ID',
width: 50,
//hidden: true,
sortable: true/*,
editor: */
}, {
header: "Code",
dataIndex: 'CODE',
width: 110,
sortable: true,
editor: new Ext.form.TextField({
allowBlank: false
})
}, {
header: "Description",
dataIndex: 'DESCRIPTION',
width: 300,
sortable: true,
editor: new Ext.form.TextField({
allowBlank: false
})
}],


viewConfig: {
forceFit: true //??? resize ???????
},

autoExpandColumn: 'Id',
title: 'AS_ROLE table',


updater: {
insertCommand: 'p_ovc_role_table.create_object_type',
updateCommand: 'p_ovc_role_table.update_object_type',
deleteCommand: 'p_ovc_role_table.delete_object_type',
prefix: 'p_'
}/*, ??? ?? ????????, ?.?. ???? ID ????????????????????
recordForm: {
ignoreFields: {
ID: false
}
}*/
});


grid.store.paramNames.start = "p_start"; //by default it is "start"
grid.store.paramNames.limit = "p_limit"; //by default it is "start"
grid.store.load({
params: {
p_start: 0,
p_limit: 30


}
});

this.getComponent('ot_grid_panel').add(grid);

mitchellsimoens
25 Nov 2011, 9:19 AM
You want to have dynamic fields in your Store?

FOONTIK
27 Nov 2011, 11:11 PM
You want to have dynamic fields in your Store?
Yes, I want dynamic fields.
I need this part "fields: xmlFn()" as dynamic part.

FOONTIK
6 Dec 2011, 1:07 AM
Hi, everyone! Sorry I didn't give clearly explanation of my problem.

The Ext.grid.GridPanel component is great, but I've found only examples where
config-params "store" and "columns" have been hard-coded. I needed these configs as dynamic configs.

I'll give code. I hope It may help someone :)



Ext.Ajax.request({
url: 'AjaxReq',//this is a servlet, which return json-object
params: {
p_start: '1',
p_limit: '25',
p_filter: ''
},
scope: this,
disableCaching: true,
callback: function(options, success, response){

response_Obj = response.responseText;
responseObj = Ext.util.JSON.decode(response_Obj);
astore = responseObj.store
acolumns = responseObj.columns

topPanel = new Ext.grid.GridPanel({
url: 'xxx.xml',
store: astore,
columns: acolumns });

var win = new Ext.Window({
...
items: [topPanel]
});

win.show();

...