0

I have am trying to implement something along the lines of Slickgrid, column with a drop down select list?

my code is; slick.editors.js ;

(function ($) {
  // register namespace
  $.extend(true, window, {
    "Slick": {
      "Editors": {
        "Text": TextEditor,
        "Integer": IntegerEditor,
        "Date": DateEditor,
        "YesNoSelect": YesNoSelectEditor,
        "Checkbox": CheckboxEditor,
        "PercentComplete": PercentCompleteEditor,
        "LongText": LongTextEditor,
        "SelectOption": SelectCellEditor
      }
    }
  });  

with the function defined futher down,

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

    this.init = function () {

        if (args.column.options) {
            opt_values = args.column.options.split(',');
        } else {
            opt_values = "yes,no".split(',');
        }
        option_str = ""
        for (i in opt_values) {
            v = opt_values[i];
            option_str += "<OPTION value='" + v + "'>" + v + "</OPTION>";
        }
        $select = $("<SELECT tabIndex='0' class='editor-select'>" + option_str + "</SELECT>");
        $select.appendTo(args.container);
        $select.focus();
    };

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

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

    this.loadValue = function (item) {
        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();
}

Then in my CSHTML

var columns = [

  { id: "color", name: "Color", field: "color", options: "Red,Green,Blue,Black,White", editor: Slick.Editors.SelectOption },
  { id: "lock", name: "Lock", field: "lock", options: "Locked,Unlocked", editor: Slick.Editors.SelectOption },
  ];


    var options = {
        enableCellNavigation: true,
        enableColumnReorder: false
    };

    $(function () {
        var data = [];
        for (var i = 0; i < 20; i++) {
           data[i] = {
           color: "Red",
           lock: "Locked"
            };
   }

the grid shows and the colour is shown as if its a regular text in a cell, but no dropdown?.

Community
  • 1
  • 1
chris
  • 551
  • 1
  • 13
  • 32
  • Have you included `slick.editors.js` in your HTML? – ganeshk Sep 06 '12 at 14:23
  • 1
    The drop-down will appear only when you are editing that cell. You are saying that there's no dropdown when editing the cell, correct? – ganeshk Sep 06 '12 at 14:29
  • Well I though I was, I was clicking in the cell and nothing was happening, but yeah I forgot to add editable: true, to my options, guess I have been staring at the code to long. Thanks! :) I'll mark that as the answer. – chris Sep 06 '12 at 14:33
  • Been there - glad to help! I added this as answer. – ganeshk Sep 06 '12 at 14:35

1 Answers1

2

The drop-down will appear only when you are editing that cell. Adding editable: true to your grid options should work I think.

ganeshk
  • 5,583
  • 3
  • 27
  • 31