-
25 Nov 2011 7:29 AM #1
not hard coded property fields of Ext.data.XmlReader ?
not hard coded property fields of Ext.data.XmlReader ?
I have xml
I want to get the variable xmlReader by url (or another), but not hard coded. How can I do that?Code:<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>
Code: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);
-
25 Nov 2011 9:19 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,682
- Vote Rating
- 435
You want to have dynamic fields in your Store?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
27 Nov 2011 11:11 PM #3
Yes, I want dynamic fields.You want to have dynamic fields in your Store?
I need this part "fields: xmlFn()" as dynamic part.
-
6 Dec 2011 1:07 AM #4
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
Code: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(); ...


Reply With Quote