EasyUI Forum
May 06, 2024, 11:01:40 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Using a multi-select combobox in editable datagrid  (Read 24663 times)
tomhj
Newbie
*
Posts: 40


View Profile
« on: July 13, 2012, 02:47:33 PM »

I'm trying to use a combobox editor set in 'multiple' mode inside an editable datagrid.  The tutorial lists an example combobox in single-selection mode (http://www.jeasyui.com/tutorial/datagrid/datagrid12.php).  Here is my editor definition for this column:

           editor: {
                type: 'combobox',
                options: {
                    url: 'GetNames?unitId=23',
                    multiple: true,
                    valueField: 'id',
                    textField: 'name'
                }
            }

GetNames returns json data like this:
[{"id":301247,"name":"Jane Doe"},{"id":307614,"name":"John Doe"},{"id":169291,"name":"Mr Blah"}]

It is close to working, except for two problems:

1)  the combobox editor selects all items in the drop down panel even if my data-providing url returns data with no 'selected' attribute.

2)  if the "selected" drop down list entries need to have the entries return with the "selected" attribute true, how does the GetNames backend handler know which row the data is to be retrieved for?  Seems like the GetNames URL needs to have an additional parameter indicating the selected entries - but that can be specified at the time of definition for the datagrid.

Any ideas how to get this to work?

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 13, 2012, 11:38:06 PM »

Try override the 'combobox' editor to support multiple selecting feature.
Code:
$.extend($.fn.datagrid.defaults.editors,{
combobox: {
init: function(container, options){
var combo = $('<input type="text">').appendTo(container);
combo.combobox(options || {});
return combo;
},
destroy: function(target){
$(target).combobox('destroy');
},
getValue: function(target){
var opts = $(target).combobox('options');
if (opts.multiple){
return $(target).combobox('getValues').join(opts.separator);
} else {
return $(target).combobox('getValue');
}
},
setValue: function(target, value){
var opts = $(target).combobox('options');
if (opts.multiple){
if (value == ''){
$(target).combobox('clear');
} else {
$(target).combobox('setValues', value.split(opts.separator));
}
} else {
$(target).combobox('setValue', value);
}
},
resize: function(target, width){
$(target).combobox('resize', width)
}
}
});
« Last Edit: July 14, 2012, 05:53:58 AM by stworthy » Logged
tomhj
Newbie
*
Posts: 40


View Profile
« Reply #2 on: July 16, 2012, 01:34:18 PM »

Thanks - that works well.
Logged
retroip
Newbie
*
Posts: 7


View Profile Email
« Reply #3 on: October 16, 2013, 03:39:26 AM »

Thank you too !
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!