1

I'm using select2 in a dropdown which is placed into a js grid (the awesome slickgrid). The dropdown works fine in all browsers, but not in Internet Explorer. Instead of showing the dropdown values it shows [object screen] for each option. It seems to be "only" a UI issue, as if a select one of the [object screen]s the correct value is selected.

Whereas the source below is probably hard to understand for somebody without slickgrid experience, but maybe somebody has encountered a similar [object screen] issue and knows what might be wrong. Thanks for your help!

enter image description here

The dropdown is created as follows:

//SETUP DAY RATE DROPDOWN OPTIONS
    var day_rate_options = [
        {value: null, screen: ""},
        {value: "1", screen: "Standard"},
        {value: "2", screen: "High"},
    ];


var columns = [
     {id: "work_package", name: "Work Package", field: "work_package", width: 180, formatter: WPFormatter, editor: Slick.Editors.DropDown, options: wp_options, sortable: false, selectable: true},
     {id: "day_rate", name: "Day Rate", field: "day_rate", width: 100, formatter: DayRateFormatter, editor: Slick.Editors.DropDown, options: day_rate_options, sortable: false, selectable: true},
     {id: "Links", name: "", field: "id", width: 50, cssClass: "cell-title", cssClass: "cell-links", formatter: LinkFormatter, selectable: false},
 ];

The slickgrid drop down editor:

function DropDownEditor(args) {
      var $select;
      var defaultValue;
      var scope = this;

      this.init = function() {
          if(args.column.options){
              option_str = ""
              options = args.column.options
              for( i in options){
                  value = options[i].value;
                  screen = options[i].screen;
                  option_str += "<OPTION value='"+value+"'>"+screen+"</OPTION>";
                }
          }
          $select = $("<SELECT tabIndex='0' class='editor-select select2-search'>"+ option_str +"</SELECT>");
          $select.appendTo(args.container);
          $select.bind("keydown.nav", function (e) {
              if (e.keyCode === $.ui.keyCode.TAB) {
                e.stopImmediatePropagation();
              }
            })
          $select.focus();
          $select.select2();
      };

      this.destroy = function() {
          $select.remove();
      };

      this.focus = function() {
          $select.focus();
      };

      this.setValue = function(value) {
          $select.val(value);
          defaultValue = value;
      };

      this.loadValue = function(item) {
          field = args.column.field;
          if(item[field + "_id"]){
              defaultValue = item[field + "_id"];
          }
          else {
              defaultValue = item[args.column.field];
          }
          $select.val(defaultValue);
      };

      this.serializeValue = function() {
          if(args.column.options){
            return $select.val();
          }else{
            return ($select.val() == "yes");
          }
      };

      this.applyValue = function(item,state) {
          item[args.column.field] = state;
      };

      this.isValueChanged = function() {
          return ($select.val() != defaultValue);
      };

      this.validate = function() {
          return {
              valid: true,
              msg: null
          };
      };
      this.init();
  }
Thomas Kremmel
  • 14,575
  • 26
  • 108
  • 177
  • I have not worked with slickgrid but what calls DropDownEditor and with what arguments. In init you're setting value and screen assuming the day_rate_options variable is passed. The this context in IE is window when called from an event (not set by jquery) this might affect the result as supposed to chome and FF. – HMR Apr 30 '13 at 08:42
  • 1
    Maybe you can install firebug for IE and dump the options variable in init console.log(options) The console.log in IE is a bit useles when it comes to logging objects but firebug should give you more info. Then go up the call stack and see if a caller depends on the this context that might affect the parameters – HMR Apr 30 '13 at 08:46
  • Thanks for your hint. Thats probably a good approach to see whats going on. Unfortunately I cannot check it now, as I have to do some other work, but will check it later on. Will let you know if I could solve the issue. – Thomas Kremmel Apr 30 '13 at 08:49
  • There is a trailing comma after your last element: `{value: "2", screen: "High"}**,**`. Depending on the version of IE this can create an additional item with the value `undefined`. And believe me: You don't want to use `for ... in` to iterate over an array. – a better oliver Apr 30 '13 at 08:59
  • I'm not a js expert. So what is a better way to iterate over an array? – Thomas Kremmel Apr 30 '13 at 09:12
  • Ok. found the answer why it should be avoided: http://stackoverflow.com/a/3010848/237690 – Thomas Kremmel Apr 30 '13 at 09:15
  • Found the issue.. "screen" obviously references to the active screen, returning x,y, height etc. :D Exchanging screen with another variable-name solved my problem..Thank you guys. – Thomas Kremmel Apr 30 '13 at 14:48

0 Answers0