Loading ...
Sorry, an error occurred while loading the content.
 

Re: [ydn-javascript] datatable issues with XML

Expand Messages
  • Satyam
    You can define your DataTable with one, possibly fake, column just to keep it happy, since it won t allow you to have no columns, then, when you receive the
    Message 1 of 2 , Feb 4, 2009
      You can define your DataTable with one, possibly fake, column just to
      keep it happy, since it won't allow you to have no columns, then, when
      you receive the data, you can use DataTable's method insertColumn to add
      the columns you want and, if the initial column is no longer required,
      you remove it. The best place to capture the definition is by
      overriding the doBeforeCallback method of the DataSource. You will have
      the XML document available there and you can pick them there. You can
      also use the "metafields" to extract that but in your case it won't save
      you much.

      As for taking data from attributes, the DataSource does that. It first
      tries to do a getElementByTagName with the field name you gave it and
      read the contents of that tag. If that fails, it will do a getAttribute
      with that same name. Your data, however, won't work because your
      problem here is not that the values come from the attributes but that
      the attribute values contain the field names. The DataSource cannot do
      that.


      Overall, your best bet in this case is to use Connection Manager's
      asyncRequest to retrieve the data, parse it yourself, extracting the
      column definitions from the first part and the data from the topics
      section, turning them into a JavaScript array and then building the
      DataTable from both pieces, using a LocalDataSource with JS_ARRAY data.

      Satyam



      michaelsharman@... wrote:
      > Hello,
      >
      > I am trying to create a datatable from xml, ideally I'd like both the
      > columns (column headings) and the rows defined in the xml. That is the
      > first problem, in that all the examples I see on the Yahoo site have
      > hard coded column headings.
      >
      > The second problem is I can't find any examples where the values of
      > the datatable rows come from xml attributes, all the examples I've
      > seen have the values coming from the xml nodes.
      >
      > Here is my sample xml:
      >
      > <config>
      > <periods>
      > <period id="m1" label="Month 1"/>
      > <period id="m2" label="Month 2"/>
      > <period id="m3" label="Month 3"/>
      > </periods>
      > <topics>
      > <topic id="recreation" label="Recreation">
      > <points period="m1" target="3"/>
      > <points period="m2" target="3"/>
      > <points period="m3" target="3"/>
      > </topic>
      > <topic id="iphonedev" label="iPhone Development">
      > <points period="m1" target="3"/>
      > <points period="m2" target="3"/>
      > <points period="m3" target="3"/>
      > </topic>
      > </topics>
      > </config>
      >
      > I'd like each "period" to be a column heading, so in the above example
      > I'd have 3 columns to this datatable.
      >
      > I'd like each "topic" to be a row, with the "points" node being a
      > column value, I'll use the 'target' attribute as the column value.
      >
      > I've setup my responseSchema and datasource etc, but I don't even know
      > if what I'm trying to do is possible. I just can't seem to get the
      > values that I want.
      >
      > Does anyone know if this is possible?
      >
      > Thanks in advance.
      >
      > Michael
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      > ------------------------------------------------------------------------
      >
      >
      > No virus found in this incoming message.
      > Checked by AVG - www.avg.com
      > Version: 8.0.233 / Virus Database: 270.10.17/1931 - Release Date: 02/02/09 19:21:00
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.