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

DataTable not sorting integers properly right away.

Expand Messages
  • Jamie
    Listed below is some of my code that I was trying to use and the numbers do want to sort right away. If I sort on the School Name first and the School ID
    Message 1 of 6 , May 30, 2008
    • 0 Attachment
      Listed below is some of my code that I was trying to use and the
      numbers do want to sort right away. If I sort on the School Name
      first and the School ID second, the numbers sort find. If by default
      I sort by School ID first, no matter how many times I click on ID, the
      sorting will not work until I click on the school name first and back
      to school id. Is this a bug or something that I am missing.

      Thanks,

      Jamie

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
      <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <title>Progressive Enhancement</title>

      <style type="text/css">
      /*margin and padding on body element
      can introduce errors in determining
      element position and are not recommended;
      we turn them off as a foundation for YUI
      CSS treatments. */
      body {
      margin:0;
      padding:0;
      }
      </style>

      <link rel="stylesheet" type="text/css"
      href="http://yui.yahooapis.com/2.5.2/build/fonts/fonts-min.css" />
      <link rel="stylesheet" type="text/css"
      href="http://yui.yahooapis.com/2.5.2/build/datatable/assets/skins/sam/datatable.css"
      />
      <script
      src="http://yui.yahooapis.com/2.5.2/build/yuiloader/yuiloader-beta-min.js"
      type="text/javascript" ></script>


      <!--there is no custom header content for this example-->

      </head>

      <body class=" yui-skin-sam">

      <h1>Progressive Enhancement</h1>

      <div class="exampleIntro">
      <p>This example creates a DataTable instance based on markup that
      already exists
      on the page. By progressively enhancing markup with higher order
      functionality,
      users who do not have JavaScript enabled are still able to view the
      page's content
      and experience core functionality.</p>

      <p>In this example's code, note that we listen for the window "load" event
      before calling our function to be sure that the original table markup
      is fully
      rendered and available as a DataSource source for our DataTable
      instance.</p>

      </div>

      <!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

      <div id="dataTable">
      <table id="myTable">
      <thead>
      <tr>
      <th>School Id</th>
      <th>School Name</th>
      </tr>

      </thead>
      <tbody>
      <tr><td>12345679</td><td>My School</td></tr>
      <tr><td>12345678</td><td>That School</td></tr>
      <tr><td>11111111</td><td>This School</td></tr>
      <tr><td>11117777</td><td>Yours School</td></tr>
      </tbody>
      </table>
      </div>

      <script type="text/javascript">
      //YAHOO.util.Event.addListener(window, "load", function() {
      var loader = new YAHOO.util.YUILoader({
      require: ["datatable"],
      loadOptional:true,
      onSuccess: function(){
      var myColumns = [{key:"id", label: "School ID", sortable:true},
      {key:"school_name", label: "School Name", sortable:true}];
      var myDataSource = new
      YAHOO.util.DataSource(YAHOO.util.Dom.get("myTable"));
      myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
      myDataSource.responseSchema = {
      fields: [{key:"id", parser:YAHOO.util.DataSource.parseNumber},
      {key:"school_name",parser:YAHOO.util.DataSource.parseString}]};
      var myDataTable = new YAHOO.widget.DataTable("dataTable",
      myColumns, myDataSource,
      {caption:"Example: Progressively Enhanced Table from Markup",
      sortedBy:{key:"id",dir:"asc"}});
      }
      });
      loader.insert();
      //});
      </script>


      </body>
      </html>
    • Jamie
      As a follow up: http://developer.yahoo.com/yui/examples/datatable/dt_enhanced_clean.html I took the code from that page. Made the quantity the sorted by as
      Message 2 of 6 , May 30, 2008
      • 0 Attachment
        As a follow up:

        http://developer.yahoo.com/yui/examples/datatable/dt_enhanced_clean.html

        I took the code from that page. Made the quantity the sorted by as
        default and it did not sort properly.
      • jennykhan
        Hi Jamie, The sortedBy property does not actually sort any data. In the case that your data is already sorted, you use that value to render the appropriate
        Message 3 of 6 , May 30, 2008
        • 0 Attachment
          Hi Jamie,

          The "sortedBy" property does not actually sort any data. In the case
          that your data is already sorted, you use that value to render the
          appropriate UI on the already-sorted Column. If you'd like to sort
          data, you should call the sortColumn() method.

          Hope that helps,
          Jenny





          --- In ydn-javascript@yahoogroups.com, "Jamie" <jamierytlewski@...>
          wrote:
          >
          > As a follow up:
          >
          >
          http://developer.yahoo.com/yui/examples/datatable/dt_enhanced_clean.htm
          l
          >
          > I took the code from that page. Made the quantity the sorted by as
          > default and it did not sort properly.
          >
        • y_lsmith
          Jamie, Additionally, there is an optimization in DataTable (that needs review, admittedly) to respond to sort requests on columns that are currently sorted, or
          Message 4 of 6 , May 30, 2008
          • 0 Attachment
            Jamie,

            Additionally, there is an optimization in DataTable (that needs
            review, admittedly) to respond to sort requests on columns that are
            currently sorted, or in your case *believe they are sorted*, to simply
            reverse the order. This is why repeated requests to resort the ID
            column failed until you requested a sort on another column.

            Luke


            --- In ydn-javascript@yahoogroups.com, "jennykhan" <jennyhan@...> wrote:
            >
            > Hi Jamie,
            >
            > The "sortedBy" property does not actually sort any data. In the case
            > that your data is already sorted, you use that value to render the
            > appropriate UI on the already-sorted Column. If you'd like to sort
            > data, you should call the sortColumn() method.
            >
            > Hope that helps,
            > Jenny
            >
            >
            >
            >
            >
            > --- In ydn-javascript@yahoogroups.com, "Jamie" <jamierytlewski@>
            > wrote:
            > >
            > > As a follow up:
            > >
            > >
            > http://developer.yahoo.com/yui/examples/datatable/dt_enhanced_clean.htm
            > l
            > >
            > > I took the code from that page. Made the quantity the sorted by as
            > > default and it did not sort properly.
            > >
            >
          • Jamie
            I am not sure if you guys are understanding what I am trying to say. The sorting and default sorting works fine (great even) with dates and text, even from the
            Message 5 of 6 , Jun 2, 2008
            • 0 Attachment
              I am not sure if you guys are understanding what I am trying to say.
              The sorting and default sorting works fine (great even) with dates and
              text, even from the start. It is numbers that it is having problems
              with if it is sorted by a number by default.

              var myDataTable = new YAHOO.widget.DataTable("dataTable", myColumns,
              myDataSource,
              {sortedBy:{key:"school_name",dir:"asc"}});

              The code above if I change to a column with a number, the table will
              not sort properly on default. I have to click another field and then
              back to the id and it will sort properly. The date and string sort
              fine from the beginning, not the numbers.

              Thanks,

              Jamie

              --- In ydn-javascript@yahoogroups.com, "y_lsmith" <lsmith@...> wrote:
              >
              > Jamie,
              >
              > Additionally, there is an optimization in DataTable (that needs
              > review, admittedly) to respond to sort requests on columns that are
              > currently sorted, or in your case *believe they are sorted*, to simply
              > reverse the order. This is why repeated requests to resort the ID
              > column failed until you requested a sort on another column.
              >
              > Luke
              >
              >
              > --- In ydn-javascript@yahoogroups.com, "jennykhan" <jennyhan@> wrote:
              > >
              > > Hi Jamie,
              > >
              > > The "sortedBy" property does not actually sort any data. In the case
              > > that your data is already sorted, you use that value to render the
              > > appropriate UI on the already-sorted Column. If you'd like to sort
              > > data, you should call the sortColumn() method.
              > >
              > > Hope that helps,
              > > Jenny
              > >
              > >
              > >
              > >
              > >
              > > --- In ydn-javascript@yahoogroups.com, "Jamie" <jamierytlewski@>
              > > wrote:
              > > >
              > > > As a follow up:
              > > >
              > > >
              > >
              http://developer.yahoo.com/yui/examples/datatable/dt_enhanced_clean.htm
              > > l
              > > >
              > > > I took the code from that page. Made the quantity the sorted by as
              > > > default and it did not sort properly.
              > > >
              > >
              >
            • y_lsmith
              ... Jamie, I guess I still don t understand what you re trying to say. Do you have a page we could look at? If not, * Are you using an HTMLTABLE type
              Message 6 of 6 , Jun 2, 2008
              • 0 Attachment
                --- In ydn-javascript@yahoogroups.com, "Jamie" <jamierytlewski@...> wrote:
                >
                > I am not sure if you guys are understanding what I am trying to say.
                > The sorting and default sorting works fine (great even) with dates and
                > text, even from the start. It is numbers that it is having problems
                > with if it is sorted by a number by default.
                >
                > var myDataTable = new YAHOO.widget.DataTable("dataTable", myColumns,
                > myDataSource,
                > {sortedBy:{key:"school_name",dir:"asc"}});
                >
                > The code above if I change to a column with a number, the table will
                > not sort properly on default. I have to click another field and then
                > back to the id and it will sort properly. The date and string sort
                > fine from the beginning, not the numbers.
                >
                > Thanks,
                >
                > Jamie
                >

                Jamie,

                I guess I still don't understand what you're trying to say. Do you
                have a page we could look at? If not,
                * Are you using an HTMLTABLE type DataSource for progressive enhancement?
                * Does your DataSource fields definition for the numeric column use
                the parser DataSource.parseNumber?
                * Is the existing table, before any JavaScript executes, sorted? If
                so, by which column?
                * Does the DataTable's constructor parameter sortedBy match the column
                the existing table is sorted by? Or correctly omitted if the table is
                not pre-sorted?
                * Have you tried removing the sortedBy configuration?
                * Does the DataTable sort incorrectly in response to a column head
                click after initialized with data pre-sorted by a column other than
                the numeric column? By the numeric column? With or without the
                sortedBy config?

                Luke
              Your message has been successfully submitted and would be delivered to recipients shortly.