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

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

Expand Messages
  • David M. Patterson
    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

    • Show all 12 messages in this topic