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

Re: local xml and datatables problem

Expand Messages
  • dpj22
    Satyam - Thank you for this reply. It is very informative. I actually deleted this post (thought I did almost immediately) because the code worked on my server
    Message 1 of 2 , Oct 29, 2008
    • 0 Attachment
      Satyam - Thank you for this reply. It is very informative. I actually
      deleted this post (thought I did almost immediately) because the code
      worked on my server - it didn't work on my PC. I noticed this when I
      tested the link...

      I just asked another question... I'll read through this post and made
      the suggested changes.

      Thanks!

      --- In ydn-javascript@yahoogroups.com, Satyam <satyam@...> wrote:
      >
      > The example is meant to show that the DataSource can read XML data
      from
      > a local variable and to do that it first loads the variable with
      that
      > data using the Connection Manager. How or even why would you have
      your
      > XML data in a local variable is up to you, possibly some strange
      > requirement of the site, the example simply loads it via the call to
      > asyncRequest. Now, the important part regarding the DataTable is,
      once
      > the o.responseXML is stored in the local variable, then you can read
      it
      > and display it with the DataTable. You don't actually need that
      > intermediate step, you can actually have the DataSource read
      directly
      > from the file.
      >
      > This is actually all you would need:
      >
      > YAHOO.util.Event.addListener(window, "load", function() {
      >
      > var myColumnDefs = [
      > {key:"name", label:"Course", sortable:true},
      > {key:"date_start", label:"Start Date"},
      > {key:"length", label:"Duration"},
      > {key:"available_spots", label:"Available Spots",
      sortable:true}
      > ];
      >
      > var myDataSource = new
      YAHOO.util.DataSource("schedule.xml");
      > myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
      > myDataSource.responseSchema = {
      > resultNode: "class",
      > fields:
      ["name","date_start","length",{key:"available_spots",
      parser:YAHOO.util.DataSource.parseNumber}]
      > };
      >
      > var myDataTable = new YAHOO.widget.DataTable("localxml",
      myColumnDefs, myDataSource);
      > });
      >
      >
      > You will have to add parsers to your fields declaration. You have
      > sortable set to true in available_spots and if you don't use
      > parseNumber, they will be sorted as strings so you will have that
      column
      > ordered lile 1, 11, 12, 2, 21, 3 and so on.
      >
      > Satyam
      >
      >
      >
      >
      > dpj22 wrote:
      > > This is a newbie question. I want to use a local xml file to
      display
      > > data about courses. I tried using the DataTable xml example and
      change
      > > around the variables to match my data. But I think I have a few
      issues
      > > with the way I'm loading the data.
      > >
      > > Code is at http://216.55.144.95/data/schedule.html
      > >
      > > The data file is schedule.xml in the same directory.
      > >
      > > I read through most of the docs but couldn't find an example of
      using
      > > a local xml file.
      > >
      > > Thanks for any help!
      > >
      > > Dan
      > >
      > >
      > > ------------------------------------
      > >
      > > Yahoo! Groups Links
      > >
      > >
      > >
      > > ------------------------------------------------------------------
      ------
      > >
      > >
      > > No virus found in this incoming message.
      > > Checked by AVG - http://www.avg.com
      > > Version: 8.0.175 / Virus Database: 270.8.4/1752 - Release Date:
      28/10/2008 10:04
      > >
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.