EasyUI Forum
May 19, 2024, 10:01:24 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: checkbox in Multiple Select of combobox  (Read 16592 times)
varonica
Full Member
***
Posts: 106


View Profile
« on: July 25, 2014, 02:16:25 AM »

Hi, i wonder if we can add checkbox to combobox(Multiple Select) . Is there a way to do that ?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 25, 2014, 09:04:00 AM »

Set 'multiple' property to true and the user can select multiple items from combobox. If you really want to add checkbox to every item, please use 'formatter' function to customize the item. Here is the simple implementation to display item checkbox.
Code:
$('#cc').combobox({
  formatter:function(row){
    var opts = $(this).combobox('options');
    return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]
  },
  onLoadSuccess:function(){
    var opts = $(this).combobox('options');
    var target = this;
    var values = $(target).combobox('getValues');
    $.map(values, function(value){
      var el = opts.finder.getEl(target, value);
      el.find('input.combobox-checkbox')._propAttr('checked', true);
    })
  },
  onSelect:function(row){
    console.log(row)
    var opts = $(this).combobox('options');
    var el = opts.finder.getEl(this, row[opts.valueField]);
    el.find('input.combobox-checkbox')._propAttr('checked', true);
  },
  onUnselect:function(row){
    var opts = $(this).combobox('options');
    var el = opts.finder.getEl(this, row[opts.valueField]);
    el.find('input.combobox-checkbox')._propAttr('checked', false);
  }
})
Logged
varonica
Full Member
***
Posts: 106


View Profile
« Reply #2 on: July 25, 2014, 06:56:29 PM »

Thanks, you're a genius!!  Cry Cry Cry Cry Kiss Kiss Kiss Kiss Kiss Embarrassed Embarrassed Embarrassed Cool Cool Cool Cool Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Wink Wink Wink
Logged
arma
Full Member
***
Posts: 110


View Profile
« Reply #3 on: August 05, 2014, 06:25:56 AM »

Hi,

I could not get the onSelect to work. Error on this line :

var el = opts.finder.getEl(this, row[opts.valueField]);

Uncaught TypeError: Cannot read property 'getEl' of undefined. I tried to console.log(opts) but it seems there's no object finder.

Thanks
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!