Author Topic: multiple select drop down editor  (Read 3460 times)

angelahlp

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 51
    • View Profile
multiple select drop down editor
« on: February 17, 2014, 10:42:23 pm »
Ok - I had the custom drop down editor working fine before I updated to Pro. now nothing seems to work right. Maybe some documentation that describes the major differences between the pro and non-pro versions - or at least a heads up that everything changes when you go pro!

I finally have the dropdownbox working, but now it disappears after I select another option. Can someone please post a dropdownbox editor that works with pro? I got the autoCompleteEditor from the Pro documentation working - but this is not what I want. The dropdownEditor example from the non-pro version does not work at all. I updated it to the following - but now the whole thing disappears if I change the select option...
 var dropDownEditor = function (ui) {

   var $cell = ui.$cell,
        dataIndx = ui.dataIndx,
        cls = ui.cls,
        dataCell = $.trim(ui.rowData[dataIndx]);
   var userindex = '';
   switch (dataIndx) {
      case 2:
         userindex = arr1;
              break;
            case 3:
         userindex = arr2;
         break;
      }
        var str = "";
        for (var i = 0; i < userindex.length; i++) {
            if (dataCell == userindex)
                str += "<option selected>" + userindex + "</option>";
            else
                str += "<option>" + userindex + "</option>";
        }
        var $sel = $('<select id="example" name="'+dataIndx+'" multiple="multiple" class="'+cls+'">' + str + "</select>")
        .appendTo($cell);
    }


PS - Anyone have an example of how I can send in the ui AND the array to the dropdownEditor in Pro? I have tried many things with no luck...
« Last Edit: February 18, 2014, 05:25:14 pm by paramquery »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: multiple select drop down editor
« Reply #1 on: February 18, 2014, 05:31:25 pm »
Edit
=======================================
Easier way to setup multiple select editor without mixing HTML markup in js is

Code: [Select]
editor: {
      type: 'select',
      attr: 'multiple',
      options: userIndex (array of strings or array of objects )
}


=========================================================
This is the working code of multiple select editor using callback function (which is quite lengthy).

Code: [Select]
        var selectEditor = function (ui) {
            var $cell = ui.$cell,
                rowData = ui.rowData,
                dataIndx = ui.dataIndx,
                cls = ui.cls,
                dc = ui.cellData,
                dc = dc ? dc : [];

            var options = ['a', 'b', 'c'],
                str="";
            for (var i = 0; i < options.length; i++) {
                var opt = options[i];
                if ($.inArray(opt, dc)!=-1)
                    str += "<option selected>" + opt + "</option>";
                else
                    str += "<option>" + opt + "</option>";
            }
            var $sel = $('<select id="example" name="' + dataIndx + '" multiple="multiple" class="' + cls + '">' + str + "</select>")
                .appendTo($cell);
        }
« Last Edit: February 20, 2014, 01:17:18 pm by paramquery »