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

Datatable default sort not working

Expand Messages
  • wizard_files3
    Hi I wrote a custom sort for a Datatable (I am using Progressive table), and specified sortedBy this column. However initial sort is wrong or not applied, but
    Message 1 of 3 , Nov 24, 2009
    • 0 Attachment
      Hi I wrote a custom sort for a Datatable (I am using Progressive table), and specified sortedBy this column. However initial sort is wrong or not applied, but when I click on column to sort - it sorts it properly according to my custom sort.
      Does anyone know why?

      Here is a code bellow:





      // Custom sorting data fucntion
      var sortDate = function(a, b, desc, field) {
      // Deal with empty values
      if(!YAHOO.lang.isValue(a)) {
      return (!YAHOO.lang.isValue(b)) ? 0 : 1;
      }
      else if(!YAHOO.lang.isValue(b)) {
      return -1;
      }

      var comp = YAHOO.util.Sort.compare;
      var compState=0;

      var aSplit=a.getData(field).split(new RegExp( "[-: ]{1}", "g" ));
      var bSplit=b.getData(field).split(new RegExp( "[-: ]{1}", "g" ));
      for(i=0;i<aSplit.length;i++)
      {
      compState = comp(aSplit[i], bSplit[i], desc);
      if(compState!=0) return compState;
      }
      };






      YAHOO.util.Event.addListener(window, "load", function() {
      YAHOO.example.EnhanceFromMarkup2 = new function() {
      var myColumnDefs = [
      {key:"start",label:"Start",sortable:true,sortOptions:{sortFunction:sortDate}},
      {key:"end",label:"End", sortable:false, sortable:true,sortOptions:{sortFunction:sortLinkDate}},
      {key:"error",label:"Error",sortable:true},
      {key:"status",label:"Status",sortable:true},
      {key:"bug",label:"Bug",sortable:false}
      ];


      this.myDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get("statAll"));
      this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
      this.myDataSource.responseSchema = {
      fields: [{key:"start"},
      {key:"end"},
      {key:"error"},
      {key:"status"},
      {key:"bug"}
      ]
      };

      this.myDataTable = new YAHOO.widget.DataTable("statMarkup", myColumnDefs, this.myDataSource,
      {caption:"All Process Stats",
      sortedBy:{key:"start", dir:YAHOO.widget.DataTable.CLASS_DESC,sortFunction:sortDate}}
      );
      };
      });
    • Satyam
      SortedBy is meant to tell the DataTable how the data came sorted from the source, so it can apply the proper visual styles. It won t sort the table but if the
      Message 2 of 3 , Nov 25, 2009
      • 0 Attachment
        SortedBy is meant to tell the DataTable how the data came sorted from
        the source, so it can apply the proper visual styles. It won't sort the
        table but if the data came sorted, say, from an SQL server, where
        sorting is usually cheap, you can tell the DataTable about that.

        Satyam

        wizard_files3 escribió:
        > Hi I wrote a custom sort for a Datatable (I am using Progressive table), and specified sortedBy this column. However initial sort is wrong or not applied, but when I click on column to sort - it sorts it properly according to my custom sort.
        > Does anyone know why?
        >
        > Here is a code bellow:
        >
        >
        >
        >
        >
        > // Custom sorting data fucntion
        > var sortDate = function(a, b, desc, field) {
        > // Deal with empty values
        > if(!YAHOO.lang.isValue(a)) {
        > return (!YAHOO.lang.isValue(b)) ? 0 : 1;
        > }
        > else if(!YAHOO.lang.isValue(b)) {
        > return -1;
        > }
        >
        > var comp = YAHOO.util.Sort.compare;
        > var compState=0;
        >
        > var aSplit=a.getData(field).split(new RegExp( "[-: ]{1}", "g" ));
        > var bSplit=b.getData(field).split(new RegExp( "[-: ]{1}", "g" ));
        > for(i=0;i<aSplit.length;i++)
        > {
        > compState = comp(aSplit[i], bSplit[i], desc);
        > if(compState!=0) return compState;
        > }
        > };
        >
        >
        >
        >
        >
        >
        > YAHOO.util.Event.addListener(window, "load", function() {
        > YAHOO.example.EnhanceFromMarkup2 = new function() {
        > var myColumnDefs = [
        > {key:"start",label:"Start",sortable:true,sortOptions:{sortFunction:sortDate}},
        > {key:"end",label:"End", sortable:false, sortable:true,sortOptions:{sortFunction:sortLinkDate}},
        > {key:"error",label:"Error",sortable:true},
        > {key:"status",label:"Status",sortable:true},
        > {key:"bug",label:"Bug",sortable:false}
        > ];
        >
        >
        > this.myDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get("statAll"));
        > this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
        > this.myDataSource.responseSchema = {
        > fields: [{key:"start"},
        > {key:"end"},
        > {key:"error"},
        > {key:"status"},
        > {key:"bug"}
        > ]
        > };
        >
        > this.myDataTable = new YAHOO.widget.DataTable("statMarkup", myColumnDefs, this.myDataSource,
        > {caption:"All Process Stats",
        > sortedBy:{key:"start", dir:YAHOO.widget.DataTable.CLASS_DESC,sortFunction:sortDate}}
        > );
        > };
        > });
        >
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
        > ------------------------------------------------------------------------
        >
        >
        > No virus found in this incoming message.
        > Checked by AVG - www.avg.com
        > Version: 9.0.709 / Virus Database: 270.14.80/2523 - Release Date: 11/24/09 08:46:00
        >
        >
      • MingoMax
        Hi, please, I am with a doubt, where are the widgets like datatable, tabview, buttons, etc from YUI2 in YUI3? Or, as these arewidgets in the new approach? For
        Message 3 of 3 , Nov 26, 2009
        • 0 Attachment
          Hi, please, I am with a doubt, where are the widgets like datatable, tabview, buttons, etc  from YUI2 in YUI3?
           Or, as these are
          widgets in the new approach?
          For the examples  in documentation  there is no how to develop with YUI3 using this widgets , today I am using a middle approach, but what about when the widgets are discontinued on YUI2 what to do or how to do?

          Tks for all.



          Mingo
          Developer.


          Veja quais são os assuntos do momento no Yahoo! + Buscados: Top 10 - Celebridades - Música - Esportes
        Your message has been successfully submitted and would be delivered to recipients shortly.