Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: How to define XML Reader Recordtypes/Fields at runtime?

  1. #1

    Default How to define XML Reader Recordtypes/Fields at runtime?

    Hello,
    I need to configure my grid at runtime. For that, I need to build up my XMLReader at runtime so that I could dynamically add columns in grid as well. I dont know how to add fields/record tpyes in xmlreader of my store. Please guide me how to do it?

  2. #2

    Default

    "DO MY JOB, PLEASE". I can offer you 25 usd per hour consultancy .

    Try to do something, write simple code , show your progress to us. May be someone will help you for free. But they will not work on you for free

  3. #3

    Default

    Trying to configure store fields from outside Ext.onready:
    Code:
    function RecieveStatusXML(str) {
            var statusXml = StringToXml(strrr);
            
            var statusStore = Ext.StoreMgr.get('statusStore');
            var childs = statusXml.documentElement.childNodes.item(0).childNodes;
            var recData = [];
            for(var x=0; x < childs.length; x++)
            {
                //recData.push(new Ext.data.Field({name: "'" + childs.item(x).tagName + "State'", mapping: "'" + childs.item(x).tagName + " > @State'" }));
                //recData.push(new Ext.data.Field({name: "'" + childs.item(x).tagName + "Description'", mapping: "'" + childs.item(x).tagName + " > @Description'" }));
                var TopicRecord = Ext.data.Record.create(
                    [
                        {name: "'" + childs.item(x).tagName + "Description'", mapping: "'" + childs.item(x).tagName + " > @Description'" },
                        {name: "'" + childs.item(x).tagName + "State'", mapping: "'" + childs.item(x).tagName + " > @State'" }
                    ]
                );
                var myNewRecord = new TopicRecord(
                    {
                        title: childs.item(x).tagName,
                        state: childs.item(x).attributes[0].nodeValue,
                        description: childs.item(x).attributes[1].nodeValue
                    }
                );
                recData.push(myNewRecord);            
            }
            statusStore.add(recData);
            //statusStore.fields = recData;
            //statusStore.load();
    	}
    Grid:
    Code:
    var statusGrid = new Ext.grid.GridPanel({
        id: 'statusGrid',
        title: 'Status',
        store: statusStore,
        hideHeaders: true,
        trackMouseOver: false,
        autoWidth: false,
        columns:
        [
            {id: '_dateAndTime', header: "DateAndTime", dataIndex: 'DateAndTime', renderer: statusRenderer}
        ],
        viewConfig: 
        {
            forceFit: true
        },
        autoExpandColumn: '_dateAndTime'
    });
    
    function statusRenderer(value, p, r)
    {
        var arr = [];
        var statusStore = Ext.StoreMgr.get('statusStore');
        statusStore.each(function(record)
        {
            arr.push(record.data.title,  '<br />', record.data.state, '<br />', record.data.description, '<br /><br />');
        });
        return arr.join('');
    }
    My Store:
    Code:
    var statusStore = new Ext.data.Store({
        storeId: 'statusStore',
        proxy: new Ext.data.MemoryProxy(''),
        reader: new Ext.data.XmlReader(
            {
                record: 'Status'
            },
            [
                {name: 'DateAndTime', mapping: '@DateAndTime'}
            ]
            )
    });
    And my XML:
    Code:
    <Statuses><Status DateAndTime='date'> <Door State='1' Description='desc' /><Acc State='2' Description='sadasd sad r' /><St State='0' Description='lpc' /> </Status></Statuses>
    Now will you try to 'help' me????

  4. #4

  5. #5
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Think a bit more about what you are doing.

    You want to create ONE record definition.

    Don't you?

    So, you only need to interrogate ONE "Status" element.

    So there's a start.

    Code:
    var dataRec = Ext.DomQuery.selectNode(myXmlDocument, "Status");
    What you ware wanting to create by iterating through that is an Array of Field definition objects. Containing named and mapping. Maybe type if you know it.

    Then you want to use that Array to create a record definition. Use DomQuery.

    You must learn to analyze problems clearly.

  6. #6
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,675

    Default

    I use the override from condor and it works perfect

    http://www.extjs.com/forum/showthread.php?t=53009
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  7. #7
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    I think the OP is wanting to create a Record definition by interrogating the first data item.

    But you're right, he'll probably want to create a column model fro the same information too.

  8. #8

    Default

    Well, the main problem is that I dont know the elements inside <Status> tag. So I thought of adding record type at run time into my xml reader. And as far as my columns are concerned, so I just need a single column and use a XTemplate in order to show all the unknown elements (inside <Status>) data....
    So, maybe I am wrong to iterate through my XML each time I get it....So what you suggest now? Guide me, I will try my best and show it to you!!!!!

  9. #9
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Iterate through the child items of the Status element.

  10. #10

    Default

    I have already done that.....what should I do after iterating all through those child elements? How can I add record fields in my store`s xmlreader?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •