3.2.0

Dynamically setting Column Text (Headers) From XML Document

I figured out how to assign column headings from the XML Table Model using xpath. Simply override the model.response() function like this.
var grid = ...; // setup grid
var model = ...; // setup model (Using XML Table of course)
var columnTextXpath = "//headers/header"; // or your own friendly xpath
var model_response = model.response;
model.response = function( xml ) {
    var hNodes = xml.selectNodes( columnTextXpath );
    if (hNodes) {
        var h = new Array();
        for( i=0; i<hNodes.length; i++ ) {
           h.push( hNodes[i].text );
        }
        grid.setColumnTexts( h );
    }
    model_response.call( model, xml );
}
model.request();

I hope someone finds this useful.
gbegley
May 3,
Thanks a lot! The code which you are posting is really very useful.
Alex (ActiveWidgets)
May 4,
Hi there - this code looks interesting..Does this still apply with the grid control in its present form?

Ideally what I need to do is define the columns titles, and the datatypes of each column all in the XML data itself.
This would then dynamically loaded into the javascript before the data is displayed.

I'm going to look into ways of doing this right now - but if anyone has a headstart here I'd love to hear about it!

Thanks,
Ryan
Ryan G (ryan.grenz@bulletonline.com)
July 26,
Hi, I tried the code but wasn't able to make it work.

My problem is, that hNodes is undefined (I think it's because window.HTMLElement is undefined). As I'm not that familiar with the html stuff I'm not sure whether HTMLElement is a typical property (I was not able to find any reference that states so) or if I have to define it (and if so how?).

I would be glad if somebody could help,
Stephan
Stephan
September 9,
Read the code again, better yet, copy and paste.

Undefined means you havent declared it

and it's clearly declared within the code specified.

also, I don't see how this piece of code has anything to do with window.HTMLElement


this may be a good time to stop doing drugs while trying to code...
Kosie
September 9,
Actually I just copied the above code.
The problem is that xml.selectNodes( columnTextXpath ); doesn't return a real value.

Ok, with window.HTMLElement I copied the wrong statement (and confused myself with it), it was window.XPathEvaluator (Ln 248 gecko.js ) which is also undefined and if I understand it correctly the statements in (function() do apply to all function within the round brackets).

So as window.XPathEvaluator is undefined he just returns.

So what can I do about the window.XPathEvaluator?

Stephan

P.S. Well to stop doing drugs one has to start with em and I'm not willing to start.
Stephan
September 9,
Stab in the dark, but do you get any data returned?

Remember, they're just overriding the response method of the grid. If no data is returned, it could be the reason why you're getting that error.

No changes (as far as I know) is needed in gecko.js unless there's a bug?

What you could try doing is put in a few alerts to see what data you're getting (if any)

Also, there's a difference between the table TEXT and table XML components. In this specific example, they're using an XML file as their data storage, whereas with TEXT, it would just do an XMLHTTPRequest to whichever page you specfied in the url.

drugs is cool, you should start
Kosie
September 9,
I assume with data you mean xml in model.response = function( xml ).
If I call alert(xml) the proper xml string is displayed (I used companies-array.xml from the examples section for test purposes).

Could it be that the XPathEvaluator is blocked or must be activated (I'm using IE 6.0.2900.2180 on XP Pro Sp2)?

Stephan
Stephan
September 9,
You should get a warning in IE6 and above asking you if you want to run dynamic content (especially if you're running it from your local PC without IIS)

Just allow it (it should then reload the page) and you should be able to see the grid etc.

Other than that I wouldn't know.
Kosie
September 9,
Well it was woth a try (I allways allowed the dynamic context to be displayed - so thats not it).

Thanks anyway, I guess I've got to dig deeper in the source and maybe I'll find something or I've to be content with static column headings.

Stephan
September 9,

This topic is archived.

See also:


Back to support forum