Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

XML for DataGrid

Explorer ,
Jul 31, 2008 Jul 31, 2008
I suck at this I guess...
Although I love and enjoy Flash and AS3.0 I just end up getting stuck everytime I solve a problem..

I've tried out different solutions for my problems but when I try to making it work on my problems it won't work. It work at some point but fail to keep my problems away.

After having loaded a xml-file I want the contents to be assigned to a DataGrid in the different columns that I need.

And, if possible, I want to sort the contents first by column A and then by column B.

But how do I assign the xml-contents/data to the DataGrid?
And how do I sort the data/contents in the DataGrid??

Thanks in advance.
TOPICS
ActionScript
753
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 31, 2008 Jul 31, 2008
Here's a very basic example of displaying xml in a DataGrid.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2008 Aug 01, 2008
I've tried something similar and it work fine.

However, the problem seem to occure when I want to import a xml-file.

I've copied and pasted your code into an xml-file, loaded it and made sure it worked.
But when I try to load my own xml-file into flash the data won't display in the grid.

I've made the changes I needed (changed the name of the the objects, etc. to fit the data I want to display in the grid) but it just won't work.

Since I've tested your xml-code in an external xml-file I would assume it would also work with the xml-file I want to load into the flash.

So, what the heck is wrong??

Here's my code for loading and trying to display the XML in flash:

import fl.data.DataProvider;
import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;

var myUrlLoader:URLLoader = new URLLoader();
var myUrlReq:URLRequest = new URLRequest("exportdisplay_bildatatest.xml");
myUrlLoader.load(myUrlReq);

myUrlLoader.addEventListener(Event.COMPLETE, dataOK);

function dataOK(e:Event):void{

var data:XML = new XML(myUrlLoader.data);


var dp:DataProvider = new DataProvider(data);
var dg:DataGrid = new DataGrid();
dg.setSize(400, 300);

var col:DataGridColumn;

col = dg.addColumn("Ã…rsmodell");
col.dataField ="Arsmodell";
col = dg.addColumn("Merke");
col.dataField ="Merke";
col = dg.addColumn("Modell");
col.dataField ="Modell";
col.sortable=false;
dg.dataProvider = dp;
addChild(dg);
}

PS!
The xml-file I want to display is an xml-file that is generated each afternoon and uploaded to a server.
Could it be that the problem lies within this proscess??
I've checked the file and it seem OK...
And when I trace it in flash the contents displays in the Output-box.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 01, 2008 Aug 01, 2008
Can you post an abridged version of the xml file?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2008 Aug 01, 2008
The XML-code:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 01, 2008 Aug 01, 2008
That XML is a little too complex for a DataProvider. But you can easily extract the nodes you need. Like so:


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2008 Aug 01, 2008
Thanks, man!!

You just solved my biggest problem so far with flash (I've been struggling for about 2 weeks with this...).

Just a few issues remaining..
How do I sort the data by "Arsmodell" and then by "Modell"?

I've also created different textbox to contain some of the other contents from the XML-file.
But how do I create links to the DataGrid that will access those other contents??

Thanks, again!
I hope some day that I can be as helpful as you guys at this forum... 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 01, 2008 Aug 01, 2008
For the sort, you can use a compare function like this:
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2008 Aug 08, 2008
Hmm..

As I was testing I discovered that the "Modell" won't sort as it should.

Any idea why?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 08, 2008 Aug 08, 2008
LATEST
Don't know what "as it should" means in this context. The "Modell" column is not sortable using the DataGrid header - if that's what you mean, just remove col.sortable=false.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines