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

Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

Expand Messages
  • shortestpath
    ok - just thought I d give a little update in case anyone was following this... my original goal was to add attributes to the ui table s tr. these attributes
    Message 1 of 12 , Nov 1, 2007
    • 0 Attachment
      ok - just thought I'd give a little update in case anyone was following this...

      my original goal was to add attributes to the ui table's tr. these attributes would include those values retrieved in the datasource but not shown in the ui table.

      here's the gist of it:


          this.myCustomFormatter = function(elCell, oRecord, oColumn, oData) {

              // getAncestor(elem, tagName)
              // gets the first ancestor node of elem whose tag name is tagName.

              var tr = getAncestor(elCell, "tr");

              if (tr) {
                  tr.setAttribute("code"    , oRecord.getData("code"));
                  tr.setAttribute("year"    , oRecord.getData("year"));
                  tr.setAttribute("month"   , oRecord.getData("month"));
                  tr.setAttribute("longdesc", oRecord.getData("longdesc"));
                  tr.setAttribute("volume"  , oRecord.getData("volume"));
              }

              elCell.innerHTML = oData;
          };


      ----- Original Message ----
      From: shortestpath <shortestpath@...>
      To: ydn-javascript@yahoogroups.com
      Sent: Thursday, November 1, 2007 2:50:24 PM
      Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

      Sorry - I had made a mistake earlier. When I said before that I added the key name to the datasource responseSchema and still got undefined, it was before that responseSchema was the one I use when I first load the table.

      But I had another event handler - and another responseSchema - for when I expand/collapse the table to re-get data. I added the key to this second responseSchema and now the value I expected shows. :)


      ----- Original Message ----
      From: shortestpath <shortestpath@ yahoo.com>
      To: ydn-javascript@ yahoogroups. com
      Sent: Thursday, November 1, 2007 2:05:43 PM
      Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

      I have tried oRecord.getData with a fieldname that is a column in my datasource that is not shown in the ui table, but I get "undefined".

      If I try with one of the other fields that -is- shown in the ui table, then oRecord.getData returns to me that value.

      Is there something else I am missing? If I add the field to my column definitions, then the colum shows up in the table (since I pass the column defs into the datatable constructor) . I'm not quite sure what datasource.response Schema does, but I even tried adding the field name into here but no luck...


      ----- Original Message ----
      From: Satyam <satyam@satyam. com.ar>
      To: ydn-javascript@ yahoogroups. com
      Sent: Thursday, November 1, 2007 11:38:45 AM
      Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

      You have the whole record available to you, just use:
       
      oRecord.getData( 'fieldname' );
       
      to get any field you want, even those not displayed
      ----- Original Message -----
      Sent: Thursday, November 01, 2007 5:36 PM
      Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

      is it possible to pass into the custom formatter function data from other columns' fields?

      from what I've read so far, it seems that in using a custom formatter, the oData from function(elCell, oRecord, oColumn, oData) always refers to the current field that you're dealing with.


      ----- Original Message ----
      From: Joe Crawford <joe@artlung. com>
      To: ydn-javascript@ yahoogroups. com
      Sent: Tuesday, October 30, 2007 7:39:14 PM
      Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

      On 10/30/07, shortestpath <shortestpath@ yahoo.com> wrote:
      > I have a datatable created from an array datasource, but I don't
      > display all the columns.
      >
      > I right-click a row from the table to bring up a context menu; I need
      > to be able to use values from the datasource that are related to the
      > right-clicked row.
      >
      > My idea was: somehow take the values from the datasource that I
      > --don't-- show in the table, and add them as attributes to the
      > generated table's tr rows. Then when I right-click to bring up the
      > context menu, I can simply look to the right-clicked row and read the
      > saved attributes there.
      >
      > Is this possible, or should I be going about this some other way?

      I think what you ask is possible, I at first wanted to do interaction
      with a context-click, but then decided to do it with a checkbox and a
      custom formatter. I put the value in the value of the checkbox, then
      in the onclick handler I pass "this" to pass the element:

      Here's my custom formatter:
      YAHOO.widget. DataTable. leaderboardForma tCheckbox = function(el,
      oRecord, oColumn, oData) {
      var bChecked = oData;
      bChecked = (bChecked) ? " checked" : "";
      // don't check things by default
      bChecked = '';
      el.innerHTML = "<div align=\"center\ "><input id=\"id"+ oData +"\"
      value=\"" + oData + "\"type=\"checkbox\ "" + bChecked +
      " class=\"" + YAHOO.widget. DataTable. CLASS_CHECKBOX + "\"
      onclick=\"updateSel ectedList( this)\" /></div>";
      };

      And here's updateSelectedList, which takes the element as a parameter:
      function updateSelectedList( el)
      {
      if(el.checked)
      {
      selectedList[ selectedList. length] = el.value;
      myDataTable. selectRow( myDataTable. getTrEl(el. id));

      } else {
      var tmparr = [];
      var tmpindex = 0;
      for(i=0;i<selectedL ist.length; i++)
      {
      if(selectedList[ i]!=el.value) {
      tmparr[tmpindex+ +] = selectedList[ i];
      }
      }
      selectedList = tmparr;
      myDataTable. unselectRow( myDataTable. getTrEl(el. id));
      }
      updateBookmarkList( selectedList) ;

      }
      This code also calls the selectRow and unselectRow methods so I get a
      visual record that the row is selected.

      This is how I did the leaderboards for FreeStyle I posted yesterday.

      Joe
      --
      http://artlung. com/
      805-857-3951



      ____________ _________ _________ _________ _________ __
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail. yahoo.com

      No virus found in this incoming message.
      Checked by AVG Free Edition.
      Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01


      ____________ _________ _________ _________ _________ __
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail. yahoo.com


      ____________ _________ _________ _________ _________ __
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail. yahoo.com


      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com
    • Satyam
      I am not sure it would work at all. I tried adding arbitrary attributes to HTML elements a couple of years ago and I found that some browsers validate what
      Message 2 of 12 , Nov 1, 2007
      • 0 Attachment
        I am not sure it would work at all.  I tried adding arbitrary attributes to HTML elements a couple of years ago and I found that some browsers validate what goes where and some don't.  What you are trying to do would be valid in an XML file, and it seemed to me then that some browsers had the document as a generic XML file, and out of that it read what it needed and ignored the rest while others would not accept any attribute that didn't belong there.  I feel that the restricting browser was the right one.  I wouldn't count on any browser at all to take attributes that don't match the DTD (the document definition) and I haven't seen anyone doing that.  I have probably read more than half the lines of code in DataTable and a few of many of the other YUI components, and I have not seen a single line that does what you are trying to do.
         
        You can retrieve that information at any time:
         
        var rec = myDataTable.getRecord(tr);
         
        So, if by whatever means you get the <TR> element, you can get the record data not by reading attributes from that TR element but by passing the reference to that TR to the getRecord method and read the data from the record.
         
        Satyam
         
         
         
         
        ----- Original Message -----
        Sent: Thursday, November 01, 2007 9:55 PM
        Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

        ok - just thought I'd give a little update in case anyone was following this...

        my original goal was to add attributes to the ui table's tr. these attributes would include those values retrieved in the datasource but not shown in the ui table.

        here's the gist of it:


            this.myCustomFormatter = function(elCell, oRecord, oColumn, oData) {

                // getAncestor(elem, tagName)
                // gets the first ancestor node of elem whose tag name is tagName.

                var tr = getAncestor(elCell, "tr");

                if (tr) {
                    tr.setAttribute("code"    , oRecord.getData("code"));
                    tr.setAttribute("year"    , oRecord.getData("year"));
                    tr.setAttribute("month"   , oRecord.getData("month"));
                    tr.setAttribute("longdesc", oRecord.getData("longdesc"));
                    tr.setAttribute("volume"  , oRecord.getData("volume"));
                }

                elCell.innerHTML = oData;
            };


        ----- Original Message ----
        From: shortestpath <shortestpath@...>
        To: ydn-javascript@yahoogroups.com
        Sent: Thursday, November 1, 2007 2:50:24 PM
        Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

        Sorry - I had made a mistake earlier. When I said before that I added the key name to the datasource responseSchema and still got undefined, it was before that responseSchema was the one I use when I first load the table.

        But I had another event handler - and another responseSchema - for when I expand/collapse the table to re-get data. I added the key to this second responseSchema and now the value I expected shows. :)


        ----- Original Message ----
        From: shortestpath <shortestpath@ yahoo.com>
        To: ydn-javascript@ yahoogroups. com
        Sent: Thursday, November 1, 2007 2:05:43 PM
        Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

        I have tried oRecord.getData with a fieldname that is a column in my datasource that is not shown in the ui table, but I get "undefined".

        If I try with one of the other fields that -is- shown in the ui table, then oRecord.getData returns to me that value.

        Is there something else I am missing? If I add the field to my column definitions, then the colum shows up in the table (since I pass the column defs into the datatable constructor) . I'm not quite sure what datasource.response Schema does, but I even tried adding the field name into here but no luck...


        ----- Original Message ----
        From: Satyam <satyam@satyam. com.ar>
        To: ydn-javascript@ yahoogroups. com
        Sent: Thursday, November 1, 2007 11:38:45 AM
        Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

        You have the whole record available to you, just use:
         
        oRecord.getData( 'fieldname' );
         
        to get any field you want, even those not displayed
        ----- Original Message -----
        Sent: Thursday, November 01, 2007 5:36 PM
        Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

        is it possible to pass into the custom formatter function data from other columns' fields?

        from what I've read so far, it seems that in using a custom formatter, the oData from function(elCell, oRecord, oColumn, oData) always refers to the current field that you're dealing with.


        ----- Original Message ----
        From: Joe Crawford <joe@artlung. com>
        To: ydn-javascript@ yahoogroups. com
        Sent: Tuesday, October 30, 2007 7:39:14 PM
        Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

        On 10/30/07, shortestpath <shortestpath@ yahoo.com> wrote:
        > I have a datatable created from an array datasource, but I don't
        > display all the columns.
        >
        > I right-click a row from the table to bring up a context menu; I need
        > to be able to use values from the datasource that are related to the
        > right-clicked row.
        >
        > My idea was: somehow take the values from the datasource that I
        > --don't-- show in the table, and add them as attributes to the
        > generated table's tr rows. Then when I right-click to bring up the
        > context menu, I can simply look to the right-clicked row and read the
        > saved attributes there.
        >
        > Is this possible, or should I be going about this some other way?

        I think what you ask is possible, I at first wanted to do interaction
        with a context-click, but then decided to do it with a checkbox and a
        custom formatter. I put the value in the value of the checkbox, then
        in the onclick handler I pass "this" to pass the element:

        Here's my custom formatter:
        YAHOO.widget. DataTable. leaderboardForma tCheckbox = function(el,
        oRecord, oColumn, oData) {
        var bChecked = oData;
        bChecked = (bChecked) ? " checked" : "";
        // don't check things by default
        bChecked = '';
        el.innerHTML = "<div align=\"center\ "><input id=\"id"+ oData +"\"
        value=\"" + oData + "\"type=\"checkbox\ "" + bChecked +
        " class=\"" + YAHOO.widget. DataTable. CLASS_CHECKBOX + "\"
        onclick=\"updateSel ectedList( this)\" /></div>";
        };

        And here's updateSelectedList, which takes the element as a parameter:
        function updateSelectedList( el)
        {
        if(el.checked)
        {
        selectedList[ selectedList. length] = el.value;
        myDataTable. selectRow( myDataTable. getTrEl(el. id));

        } else {
        var tmparr = [];
        var tmpindex = 0;
        for(i=0;i<selectedL ist.length; i++)
        {
        if(selectedList[ i]!=el.value) {
        tmparr[tmpindex+ +] = selectedList[ i];
        }
        }
        selectedList = tmparr;
        myDataTable. unselectRow( myDataTable. getTrEl(el. id));
        }
        updateBookmarkList( selectedList) ;

        }
        This code also calls the selectRow and unselectRow methods so I get a
        visual record that the row is selected.

        This is how I did the leaderboards for FreeStyle I posted yesterday.

        Joe
        --
        http://artlung. com/
        805-857-3951



        ____________ _________ _________ _________ _________ __
        Do You Yahoo!?
        Tired of spam? Yahoo! Mail has the best spam protection around
        http://mail. yahoo.com

        No virus found in this incoming message.
        Checked by AVG Free Edition.
        Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01


        ____________ _________ _________ _________ _________ __
        Do You Yahoo!?
        Tired of spam? Yahoo! Mail has the best spam protection around
        http://mail. yahoo.com


        ____________ _________ _________ _________ _________ __
        Do You Yahoo!?
        Tired of spam? Yahoo! Mail has the best spam protection around
        http://mail. yahoo.com


        __________________________________________________
        Do You Yahoo!?
        Tired of spam? Yahoo! Mail has the best spam protection around
        http://mail.yahoo.com


        No virus found in this incoming message.
        Checked by AVG Free Edition.
        Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01
      • David M. Patterson
        You can use the setAttribute() method to add new attributes to entities. Naturally, you need to use getAttribute to retrieve these attributes. I think that
        Message 3 of 12 , Nov 1, 2007
        • 0 Attachment

          You can use the setAttribute() method to add new attributes to entities. Naturally, you need to use getAttribute to retrieve these attributes.
          I think that this works for pretty much everything after IE 5.5

           

          Good luck,


          Dave

           

          -----Original Message-----
          From: ydn-javascript@yahoogroups.com [mailto:ydn-javascript@yahoogroups.com] On Behalf Of Satyam
          Sent:
          Thursday, November 01, 2007 2:37 PM
          To: ydn-javascript@yahoogroups.com
          Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

           

          I am not sure it would work at all.  I tried adding arbitrary attributes to HTML elements a couple of years ago and I found that some browsers validate what goes where and some don't.  What you are trying to do would be valid in an XML file, and it seemed to me then that some browsers had the document as a generic XML file, and out of that it read what it needed and ignored the rest while others would not accept any attribute that didn't belong there.  I feel that the restricting browser was the right one.  I wouldn't count on any browser at all to take attributes that don't match the DTD (the document definition) and I haven't seen anyone doing that.  I have probably read more than half the lines of code in DataTable and a few of many of the other YUI components, and I have not seen a single line that does what you are trying to do.

           

          You can retrieve that information at any time:

           

          var rec = myDataTable. getRecord( tr);

           

          So, if by whatever means you get the <TR> element, you can get the record data not by reading attributes from that TR element but by passing the reference to that TR to the getRecord method and read the data from the record.

           

          Satyam

           

           

           

           

          ----- Original Message -----

          Sent: Thursday, November 01, 2007 9:55 PM

          Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

           

          ok - just thought I'd give a little update in case anyone was following this...

          my original goal was to add attributes to the ui table's tr. these attributes would include those values retrieved in the datasource but not shown in the ui table.

          here's the gist of it:


              this.myCustomFormat ter = function(elCell, oRecord, oColumn, oData) {

                  // getAncestor( elem, tagName)
                  // gets the first ancestor node of elem whose tag name is tagName.

                  var tr = getAncestor( elCell, "tr");

                  if (tr) {
                      tr.setAttribute( "code"    , oRecord.getData( "code"));
                      tr.setAttribute( "year"    , oRecord.getData( "year"));
                      tr.setAttribute( "month"   , oRecord.getData( "month")) ;
                      tr.setAttribute( "longdesc" , oRecord.getData( "longdesc" ));
                      tr.setAttribute( "volume"  , oRecord.getData( "volume") );
                  }

                  elCell.innerHTML = oData;
              };

          ----- Original Message ----
          From: shortestpath <shortestpath@ yahoo.com>
          To: ydn-javascript@ yahoogroups. com
          Sent: Thursday, November 1, 2007 2:50:24 PM
          Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

          Sorry - I had made a mistake earlier. When I said before that I added the key name to the datasource responseSchema and still got undefined, it was before that responseSchema was the one I use when I first load the table.

          But I had another event handler - and another responseSchema - for when I expand/collapse the table to re-get data. I added the key to this second responseSchema and now the value I expected shows. :)

          ----- Original Message ----
          From: shortestpath <shortestpath@ yahoo.com>
          To: ydn-javascript@ yahoogroups. com
          Sent: Thursday, November 1, 2007 2:05:43 PM
          Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

          I have tried oRecord.getData with a fieldname that is a column in my datasource that is not shown in the ui table, but I get "undefined".

          If I try with one of the other fields that -is- shown in the ui table, then oRecord.getData returns to me that value.

          Is there something else I am missing? If I add the field to my column definitions, then the colum shows up in the table (since I pass the column defs into the datatable constructor) . I'm not quite sure what datasource.response Schema does, but I even tried adding the field name into here but no luck...

          ----- Original Message ----
          From: Satyam <satyam@satyam. com.ar>
          To: ydn-javascript@ yahoogroups. com
          Sent: Thursday, November 1, 2007 11:38:45 AM
          Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

          You have the whole record available to you, just use:

           

          oRecord.getData( 'fieldname' );

           

          to get any field you want, even those not displayed

          ----- Original Message -----

          Sent: Thursday, November 01, 2007 5:36 PM

          Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

           

          is it possible to pass into the custom formatter function data from other columns' fields?

          from what I've read so far, it seems that in using a custom formatter, the oData from function(elCell, oRecord, oColumn, oData) always refers to the current field that you're dealing with.

          ----- Original Message ----
          From: Joe Crawford <joe@artlung. com>
          To: ydn-javascript@ yahoogroups. com
          Sent: Tuesday, October 30, 2007 7:39:14 PM
          Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

          On 10/30/07, shortestpath <shortestpath@ yahoo.com> wrote:
          > I have a datatable created from an array datasource, but I don't
          > display all the columns.
          >
          > I right-click a row from the table to bring up a context menu; I need
          > to be able to use values from the datasource that are related to the
          > right-clicked row.
          >
          > My idea was: somehow take the values from the datasource that I
          > --don't-- show in the table, and add them as attributes to the
          > generated table's tr rows. Then when I right-click to bring up the
          > context menu, I can simply look to the right-clicked row and read the
          > saved attributes there.
          >
          > Is this possible, or should I be going about this some other way?

          I think what you ask is possible, I at first wanted to do interaction
          with a context-click, but then decided to do it with a checkbox and a
          custom formatter. I put the value in the value of the checkbox, then
          in the onclick handler I pass "this" to pass the element:

          Here's my custom formatter:
          YAHOO.widget. DataTable. leaderboardForma tCheckbox = function(el,
          oRecord, oColumn, oData) {
          var bChecked = oData;
          bChecked = (bChecked) ? " checked" : "";
          // don't check things by default
          bChecked = '';
          el.innerHTML = "<div align=\"center\ "><input id=\"id"+ oData +"\"
          value=\"" + oData + "\"type=\"checkbox\ "" + bChecked +
          " class=\"" + YAHOO.widget. DataTable. CLASS_CHECKBOX + "\"
          onclick=\"updateSel ectedList( this)\" /></div>";
          };

          And here's updateSelectedList, which takes the element as a parameter:
          function updateSelectedList( el)
          {
          if(el.checked)
          {
          selectedList[ selectedList. length] = el.value;
          myDataTable. selectRow( myDataTable. getTrEl(el. id));

          } else {
          var tmparr = [];
          var tmpindex = 0;
          for(i=0;i<selectedL ist.length; i++)
          {
          if(selectedList[ i]!=el.value) {
          tmparr[tmpindex+ +] = selectedList[ i];
          }
          }
          selectedList = tmparr;
          myDataTable. unselectRow( myDataTable. getTrEl(el. id));
          }
          updateBookmarkList( selectedList) ;

          }
          This code also calls the selectRow and unselectRow methods so I get a
          visual record that the row is selected.

          This is how I did the leaderboards for FreeStyle I posted yesterday.

          Joe
          --
          http://artlung. com/
          805-857-3951

           


          ____________ _________ _________ _________ _________ __
          Do You Yahoo!?
          Tired of spam? Yahoo! Mail has the best spam protection around
          http://mail. yahoo.com

          No virus found in this incoming message.
          Checked by AVG Free Edition.
          Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01

           


          ____________ _________ _________ _________ _________ __
          Do You Yahoo!?
          Tired of spam? Yahoo! Mail has the best spam protection around
          http://mail. yahoo.com

           


          ____________ _________ _________ _________ _________ __
          Do You Yahoo!?
          Tired of spam? Yahoo! Mail has the best spam protection around
          http://mail. yahoo.com

           


          ____________ _________ _________ _________ _________ __
          Do You Yahoo!?
          Tired of spam? Yahoo! Mail has the best spam protection around
          http://mail. yahoo.com


          No virus found in this incoming message.
          Checked by AVG Free Edition.
          Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01

        • Satyam
          You are right, it mostly works, but if you see the compatibility tables at: http://www.quirksmode.org/dom/w3c_core.html#attributes you can see it is the
          Message 4 of 12 , Nov 2, 2007
          • 0 Attachment
          • David M. Patterson
            Satyam, Thanks for the link. That s a handy site. A note about the tables and less green , though. For setAttribute() and getAttribute(), he marks IE as
            Message 5 of 12 , Nov 2, 2007
            • 0 Attachment

              Satyam,

              Thanks for the link. That’s a handy site.

               

              A note about the tables and “less green”, though.

              For setAttribute() and getAttribute(), he marks IE  as incomplete not because they don’t
              work for custom attributes, but because they don’t work for style and almost on Opera
              for a similar reason.


              I have successfully used these with IE 6, Firefox 2, Opera 9, and
              Safari 2.

               

              For whatever it’s worth.

               

              Thanks,

              Dave

               

              -----Original Message-----
              From: ydn-javascript@yahoogroups.com [mailto:ydn-javascript@yahoogroups.com] On Behalf Of Satyam
              Sent: Friday, November 02, 2007 1:08 AM
              To: ydn-javascript@yahoogroups.com
              Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

               

              You are right, it mostly works, but if you see the compatibility tables at:

               

               

              you can see it is the section with less green boxes in the whole page, which means it is not very trustworthy across browsers and, there being a way to avoid the risk of bumping into any incompatibility, why risk it.

               

              Satyam

               

              ----- Original Message -----

              Sent: Thursday, November 01, 2007 11:02 PM

              Subject: RE: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

               

              You can use the setAttribute( ) method to add new attributes to entities. Naturally, you need to use getAttribute to retrieve these attributes.
              I think that this works for pretty much everything after IE 5.5

               

              Good luck,


              Dave

               

              -----Original Message-----
              From: ydn-javascript@ yahoogroups. com [mailto:ydn- javascript@ yahoogroups. com] On Behalf Of Satyam
              Sent: Thursday, November 01, 2007 2:37 PM
              To: ydn-javascript@ yahoogroups. com
              Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

               

              I am not sure it would work at all.  I tried adding arbitrary attributes to HTML elements a couple of years ago and I found that some browsers validate what goes where and some don't.  What you are trying to do would be valid in an XML file, and it seemed to me then that some browsers had the document as a generic XML file, and out of that it read what it needed and ignored the rest while others would not accept any attribute that didn't belong there.  I feel that the restricting browser was the right one.  I wouldn't count on any browser at all to take attributes that don't match the DTD (the document definition) and I haven't seen anyone doing that.  I have probably read more than half the lines of code in DataTable and a few of many of the other YUI components, and I have not seen a single line that does what you are trying to do.

               

              You can retrieve that information at any time:

               

              var rec = myDataTable. getRecord( tr);

               

              So, if by whatever means you get the <TR> element, you can get the record data not by reading attributes from that TR element but by passing the reference to that TR to the getRecord method and read the data from the record.

               

              Satyam

               

               

               

               

              ----- Original Message -----

              Sent: Thursday, November 01, 2007 9:55 PM

              Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

               

              ok - just thought I'd give a little update in case anyone was following this...

              my original goal was to add attributes to the ui table's tr. these attributes would include those values retrieved in the datasource but not shown in the ui table.

              here's the gist of it:


                  this.myCustomFormat ter = function(elCell, oRecord, oColumn, oData) {

                      // getAncestor( elem, tagName)
                      // gets the first ancestor node of elem whose tag name is tagName.

                      var tr = getAncestor( elCell, "tr");

                      if (tr) {
                          tr.setAttribute( "code"    , oRecord.getData( "code"));
                          tr.setAttribute( "year"    , oRecord.getData( "year"));
                          tr.setAttribute( "month"   , oRecord.getData( "month")) ;
                          tr.setAttribute( "longdesc" , oRecord.getData( "longdesc" ));
                          tr.setAttribute( "volume"  , oRecord.getData( "volume") );
                      }

                      elCell.innerHTML = oData;
                  };

              ----- Original Message ----
              From: shortestpath <shortestpath@ yahoo.com>
              To: ydn-javascript@ yahoogroups. com
              Sent: Thursday, November 1, 2007 2:50:24 PM
              Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

              Sorry - I had made a mistake earlier. When I said before that I added the key name to the datasource responseSchema and still got undefined, it was before that responseSchema was the one I use when I first load the table.

              But I had another event handler - and another responseSchema - for when I expand/collapse the table to re-get data. I added the key to this second responseSchema and now the value I expected shows. :)

              ----- Original Message ----
              From: shortestpath <shortestpath@ yahoo.com>
              To: ydn-javascript@ yahoogroups. com
              Sent: Thursday, November 1, 2007 2:05:43 PM
              Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

              I have tried oRecord.getData with a fieldname that is a column in my datasource that is not shown in the ui table, but I get "undefined".

              If I try with one of the other fields that -is- shown in the ui table, then oRecord.getData returns to me that value.

              Is there something else I am missing? If I add the field to my column definitions, then the colum shows up in the table (since I pass the column defs into the datatable constructor) . I'm not quite sure what datasource.response Schema does, but I even tried adding the field name into here but no luck...

              ----- Original Message ----
              From: Satyam <satyam@satyam. com.ar>
              To: ydn-javascript@ yahoogroups. com
              Sent: Thursday, November 1, 2007 11:38:45 AM
              Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

              You have the whole record available to you, just use:

               

              oRecord.getData( 'fieldname' );

               

              to get any field you want, even those not displayed

              ----- Original Message -----

              Sent: Thursday, November 01, 2007 5:36 PM

              Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

               

              is it possible to pass into the custom formatter function data from other columns' fields?

              from what I've read so far, it seems that in using a custom formatter, the oData from function(elCell, oRecord, oColumn, oData) always refers to the current field that you're dealing with.

              ----- Original Message ----
              From: Joe Crawford <joe@artlung. com>
              To: ydn-javascript@ yahoogroups. com
              Sent: Tuesday, October 30, 2007 7:39:14 PM
              Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

              On 10/30/07, shortestpath <shortestpath@ yahoo.com> wrote:
              > I have a datatable created from an array datasource, but I don't
              > display all the columns.
              >
              > I right-click a row from the table to bring up a context menu; I need
              > to be able to use values from the datasource that are related to the
              > right-clicked row.
              >
              > My idea was: somehow take the values from the datasource that I
              > --don't-- show in the table, and add them as attributes to the
              > generated table's tr rows. Then when I right-click to bring up the
              > context menu, I can simply look to the right-clicked row and read the
              > saved attributes there.
              >
              > Is this possible, or should I be going about this some other way?

              I think what you ask is possible, I at first wanted to do interaction
              with a context-click, but then decided to do it with a checkbox and a
              custom formatter. I put the value in the value of the checkbox, then
              in the onclick handler I pass "this" to pass the element:

              Here's my custom formatter:
              YAHOO.widget. DataTable. leaderboardForma tCheckbox = function(el,
              oRecord, oColumn, oData) {
              var bChecked = oData;
              bChecked = (bChecked) ? " checked" : "";
              // don't check things by default
              bChecked = '';
              el.innerHTML = "<div align=\"center\ "><input id=\"id"+ oData +"\"
              value=\"" + oData + "\"type=\"checkbox\ "" + bChecked +
              " class=\"" + YAHOO.widget. DataTable. CLASS_CHECKBOX + "\"
              onclick=\"updateSel ectedList( this)\" /></div>";
              };

              And here's updateSelectedList, which takes the element as a parameter:
              function updateSelectedList( el)
              {
              if(el.checked)
              {
              selectedList[ selectedList. length] = el.value;
              myDataTable. selectRow( myDataTable. getTrEl(el. id));

              } else {
              var tmparr = [];
              var tmpindex = 0;
              for(i=0;i<selectedL ist.length; i++)
              {
              if(selectedList[ i]!=el.value) {
              tmparr[tmpindex+ +] = selectedList[ i];
              }
              }
              selectedList = tmparr;
              myDataTable. unselectRow( myDataTable. getTrEl(el. id));
              }
              updateBookmarkList( selectedList) ;

              }
              This code also calls the selectRow and unselectRow methods so I get a
              visual record that the row is selected.

              This is how I did the leaderboards for FreeStyle I posted yesterday.

              Joe
              --
              http://artlung. com/
              805-857-3951

               


              ____________ _________ _________ _________ _________ __
              Do You Yahoo!?
              Tired of spam? Yahoo! Mail has the best spam protection around
              http://mail. yahoo.com

              No virus found in this incoming message.
              Checked by AVG Free Edition.
              Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01

               



              (Message over 64 KB, truncated)

            • shortestpath
              Thank you for all of your inputs everyone. I think I m gonna end up going with Satyam s suggestion of grabbing the datatable s record from the corresponding
              Message 6 of 12 , Nov 2, 2007
              • 0 Attachment
                Thank you for all of your inputs everyone.

                I think I'm gonna end up going with Satyam's suggestion of grabbing the datatable's record from the corresponding html row. I like that I don't have to employ the indirect method of setting the attributes in the html tr via a custom formatter function. It saves from having to output a lot of redundant information that is already available to me in the datatable record via the html row.


                ----- Original Message ----
                From: David M. Patterson <dplhenterprises@...>
                To: ydn-javascript@yahoogroups.com
                Sent: Friday, November 2, 2007 8:24:54 AM
                Subject: RE: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                Satyam,

                Thanks for the link. That’s a handy site.

                 

                A note about the tables and “less green”, though.

                For setAttribute( ) and getAttribute( ), he marks IE  as incomplete not because they don’t
                work for custom attributes, but because they don’t work for style and almost on Opera
                for a similar reason.


                I have successfully used these with IE 6, Firefox 2, Opera 9, and
                Safari 2.

                 

                For whatever it’s worth.

                 

                Thanks,

                Dave

                 

                -----Original Message-----
                From: ydn-javascript@ yahoogroups. com [mailto:ydn- javascript@ yahoogroups. com] On Behalf Of Satyam
                Sent: Friday, November 02, 2007 1:08 AM
                To: ydn-javascript@ yahoogroups. com
                Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                 

                You are right, it mostly works, but if you see the compatibility tables at:

                 

                 

                you can see it is the section with less green boxes in the whole page, which means it is not very trustworthy across browsers and, there being a way to avoid the risk of bumping into any incompatibility, why risk it.

                 

                Satyam

                 

                ----- Original Message -----

                Sent: Thursday, November 01, 2007 11:02 PM

                Subject: RE: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                 

                You can use the setAttribute( ) method to add new attributes to entities. Naturally, you need to use getAttribute to retrieve these attributes.
                I think that this works for pretty much everything after IE 5.5

                 

                Good luck,


                Dave

                 

                -----Original Message-----
                From: ydn-javascript@ yahoogroups. com [mailto:ydn- javascript@ yahoogroups. com] On Behalf Of Satyam
                Sent: Thursday, November 01, 2007 2:37 PM
                To: ydn-javascript@ yahoogroups. com
                Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                 

                I am not sure it would work at all.  I tried adding arbitrary attributes to HTML elements a couple of years ago and I found that some browsers validate what goes where and some don't.  What you are trying to do would be valid in an XML file, and it seemed to me then that some browsers had the document as a generic XML file, and out of that it read what it needed and ignored the rest while others would not accept any attribute that didn't belong there.  I feel that the restricting browser was the right one.  I wouldn't count on any browser at all to take attributes that don't match the DTD (the document definition) and I haven't seen anyone doing that.  I have probably read more than half the lines of code in DataTable and a few of many of the other YUI components, and I have not seen a single line that does what you are trying to do.

                 

                You can retrieve that information at any time:

                 

                var rec = myDataTable. getRecord( tr);

                 

                So, if by whatever means you get the <TR> element, you can get the record data not by reading attributes from that TR element but by passing the reference to that TR to the getRecord method and read the data from the record.

                 

                Satyam

                 

                 

                 

                 

                ----- Original Message -----

                Sent: Thursday, November 01, 2007 9:55 PM

                Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                 

                ok - just thought I'd give a little update in case anyone was following this...

                my original goal was to add attributes to the ui table's tr. these attributes would include those values retrieved in the datasource but not shown in the ui table.

                here's the gist of it:


                    this.myCustomFormat ter = function(elCell, oRecord, oColumn, oData) {

                        // getAncestor( elem, tagName)
                        // gets the first ancestor node of elem whose tag name is tagName.

                        var tr = getAncestor( elCell, "tr");

                        if (tr) {
                            tr.setAttribute( "code"    , oRecord.getData( "code"));
                            tr.setAttribute( "year"    , oRecord.getData( "year"));
                            tr.setAttribute( "month"   , oRecord.getData( "month")) ;
                            tr.setAttribute( "longdesc" , oRecord.getData( "longdesc" ));
                            tr.setAttribute( "volume"  , oRecord.getData( "volume") );
                        }

                        elCell.innerHTML = oData;
                    };

                ----- Original Message ----
                From: shortestpath <shortestpath@ yahoo.com>
                To: ydn-javascript@ yahoogroups. com
                Sent: Thursday, November 1, 2007 2:50:24 PM
                Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                Sorry - I had made a mistake earlier. When I said before that I added the key name to the datasource responseSchema and still got undefined, it was before that responseSchema was the one I use when I first load the table.

                But I had another event handler - and another responseSchema - for when I expand/collapse the table to re-get data. I added the key to this second responseSchema and now the value I expected shows. :)

                ----- Original Message ----
                From: shortestpath <shortestpath@ yahoo.com>
                To: ydn-javascript@ yahoogroups. com
                Sent: Thursday, November 1, 2007 2:05:43 PM
                Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                I have tried oRecord.getData with a fieldname that is a column in my datasource that is not shown in the ui table, but I get "undefined".

                If I try with one of the other fields that -is- shown in the ui table, then oRecord.getData returns to me that value.

                Is there something else I am missing? If I add the field to my column definitions, then the colum shows up in the table (since I pass the column defs into the datatable constructor) . I'm not quite sure what datasource.response Schema does, but I even tried adding the field name into here but no luck...

                ----- Original Message ----
                From: Satyam <satyam@satyam. com.ar>
                To: ydn-javascript@ yahoogroups. com
                Sent: Thursday, November 1, 2007 11:38:45 AM
                Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                You have the whole record available to you, just use:

                 

                oRecord.getData( 'fieldname' );

                 

                to get any field you want, even those not displayed

                ----- Original Message -----

                Sent: Thursday, November 01, 2007 5:36 PM

                Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                 

                is it possible to pass into the custom formatter function data from other columns' fields?

                from what I've read so far, it seems that in using a custom formatter, the oData from function(elCell, oRecord, oColumn, oData) always refers to the current field that you're dealing with.

                ----- Original Message ----
                From: Joe Crawford <joe@artlung. com>
                To: ydn-javascript@ yahoogroups. com
                Sent: Tuesday, October 30, 2007 7:39:14 PM
                Subject: Re: [ydn-javascript] custom attributes in datatabe TR for use in contextmenu

                On 10/30/07, shortestpath <shortestpath@ yahoo.com> wrote:
                > I have a datatable created from an array datasource, but I don't
                > display all the columns.
                >
                > I right-click a row from the table to bring up a context menu; I need
                > to be able to use values from the datasource that are related to the
                > right-clicked row.
                >
                > My idea was: somehow take the values from the datasource that I
                > --don't-- show in the table, and add them as attributes to the
                > generated table's tr rows. Then when I right-click to bring up the
                > context menu, I can simply look to the right-clicked row and read the
                > saved attributes there.
                >
                > Is this possible, or should I be going about this some other way?

                I think what you ask is possible, I at first wanted to do interaction
                with a context-click, but then decided to do it with a checkbox and a
                custom formatter. I put the value in the value of the checkbox, then
                in the onclick handler I pass "this" to pass the element:

                Here's my custom formatter:
                YAHOO.widget. DataTable. leaderboardForma tCheckbox = function(el,
                oRecord, oColumn, oData) {
                var bChecked = oData;
                bChecked = (bChecked) ? " checked" : "";
                // don't check things by default
                bChecked = '';
                el.innerHTML = "<div align=\"center\ "><input id=\"id"+ oData +"\"
                value=\"" + oData + "\"type=\"checkbox\ "" + bChecked +
                " class=\"" + YAHOO.widget. DataTable. CLASS_CHECKBOX + "\"
                onclick=\"updateSel ectedList( this)\" /></div>";
                };

                And here's updateSelectedList, which takes the element as a parameter:
                function updateSelectedList( el)
                {
                if(el.checked)
                {
                selectedList[ selectedList. length] = el.value;
                myDataTable. selectRow( myDataTable. getTrEl(el. id));

                } else {
                var tmparr = [];
                var tmpindex = 0;
                for(i=0;i<selectedL ist.length; i++)
                {
                if(selectedList[ i]!=el.value) {
                tmparr[tmpindex+ +] = selectedList[ i];
                }
                }
                selectedList = tmparr;
                myDataTable. unselectRow( myDataTable. getTrEl(el. id));
                }
                updateBookmarkList( selectedList) ;

                }
                This code also calls the selectRow and unselectRow methods so I get a
                visual record that the row is selected.

                This is how I did the leaderboards for FreeStyle I posted yesterday.

                Joe
                --
                http://artlung. com/
                805-857-3951

                 


                ____________ _________ _________ _________ _________ __
                Do You Yahoo!?
                Tired of spam? Yahoo! Mail has the best spam protection around
                http://mail. yahoo.com

                No virus found in this incoming message.
                Checked by AVG Free Edition.
                Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01

                 


                ____________ _________ _________ _________ _________ __
                Do You Yahoo!?
                Tired of spam? Yahoo! Mail has the best spam protection around
                http://mail. yahoo.com

                 


                ____________ _________ _________ _________ _________ __
                Do You Yahoo!?
                Tired of spam? Yahoo! Mail has the best spam protection around
                http://mail. yahoo.com

                 


                ____________ _________ _________ _________ _________ __
                Do You Yahoo!?
                Tired of spam? Yahoo! Mail has the best spam protection around
                http://mail. yahoo.com


                No virus found in this incoming message.
                Checked by AVG Free Edition.
                Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01


                No virus found in this incoming message.
                Checked by AVG Free Edition.
                Version: 7.5.503 / Virus Database: 269.15.17/1103 - Release Date: 01/11/2007 6:01



                __________________________________________________
                Do You Yahoo!?
                Tired of spam? Yahoo! Mail has the best spam protection around
                http://mail.yahoo.com
              Your message has been successfully submitted and would be delivered to recipients shortly.