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

Re: [ydn-javascript] Problem with label-value in a DropDownCellEditor

Expand Messages
  • Satyam
    Dropdown handling has never been the best in DataTable. There are two different options, you can have a dropdown shown at all times or you can have the label
    Message 1 of 3 , Feb 7, 2009
    • 0 Attachment
      Dropdown handling has never been the best in DataTable. There are two
      different options, you can have a dropdown shown at all times or you can
      have the label and on clicking, have the cell editor show up. Many
      people prefer the first one since it takes less clicking, others the
      second, since it avoids inadvertent changes.

      For the first version you use the dropdown formatter, not the dropdown
      cell editor. It will draw a dropdown with all the options but does not
      handle the changes to the dropdown automatically as the cell editor
      does, so it is up to you to respond to the change event on the
      dropdown. You can see it working in:

      http://satyam.com.ar/yui/2.6.0/assortedControls.html

      The other option is to pop up the cell editor. The problem with this is
      that it has no formatter associated to handle the regular display of the
      label when a certain value is shown, and you cannot use the dropdown
      formatter because it will show a full, active dropdown, not just the
      label, so you have to do your own formatter, which isn't hard, but seems
      a little silly that you should have to deal with such minor issue.

      So, you just add your own formatter:

      {
      key:"educationalUnitType",
      label:"Tipo de Unidad",
      sortable: false,
      editor: new
      YAHOO.widget.DropdownCellEditor({dropdownOptions:comboUnitType.listaTiposUD,disableBtns:true}),
      formatter: function(el, oRecord, oColumn, oData) {
      var combo = comboUnitType.listaTiposUD;
      for (var i = 0;i<combo.length;i++) {
      if (oData == combo[i].value) {
      el.innerHTML = combo[i].label;
      return;
      }
      }
      }
      }

      I haven't tested this code, there might be some silly thing missing, but
      that's the general idea.

      Satyam




      Rub wrote:
      >
      > Hi, I´m really new to YUI and I need a little help with the
      > DropDownCellEditor.
      >
      > I have a table with 3 columns: 2 text columns and 1 dropdown with the
      > DropDownCellEditor implemented.
      >
      > So, my problem is that the label is only represented in the dropdown
      > but not in the table, when I choose one of the options it will write
      > the value in the table. The value is a numeric identifier for an
      > object, so what I´m trying to achieve is representing always the label
      > on page, but saving the value underneath.
      >
      > My list for the dropdown is something like this:
      >
      > comboUnitType = {listaTiposUD:
      > [ {label:"H", value:1}, {label:"UDE", value:2},
      > ...........{label:"UDPPC", value:6} ]}
      >
      > While the column definition is like this:
      >
      > {
      > key:"educationalUnitType",
      > label:"Tipo de Unidad",
      > sortable: false,
      > editor: new
      > YAHOO.widget.DropdownCellEditor({dropdownOptions:comboUnitType.listaTiposUD,disableBtns:true})
      > }
      >
      > What I get for this is the label in the cell editor but the numeric
      > value in the table.
      >
      > Any suggestions? Thanks...
      >
      >
      >
      >
      >
      >
      > ------------------------------------------------------------------------
      >
      >
      > No virus found in this incoming message.
      > Checked by AVG - http://www.avg.com
      > Version: 8.0.176 / Virus Database: 270.10.12/1909 - Release Date: 22/01/2009 7:08
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.