EasyUI Forum
May 21, 2024, 07:04:22 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: Datagrid switchbutton editor  (Read 8344 times)
battlezad
Newbie
*
Posts: 44


View Profile
« on: July 16, 2015, 12:16:04 AM »

Hi,
is it possible to extend datagrid editors with switchbutton?

Thanks in advance,
btz
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 on: July 16, 2015, 01:31:50 AM »

Yes, please try this:
Code:
<script type="text/javascript">
$.extend($.fn.datagrid.defaults.editors, {
switchbutton:{
init: function(container, options){
var input = $('<input>').appendTo(container);
input.switchbutton(options);
return input;
},
getValue: function(target){
return $(target).switchbutton('options').checked;
},
setValue: function(target, value){
$(target).switchbutton(value?'check':'uncheck');
},
resize: function(target, width){
$(target).switchbutton('resize', {width: width,height:22});
}
}
})
</script>
Logged
battlezad
Newbie
*
Posts: 44


View Profile
« Reply #2 on: July 16, 2015, 01:52:08 AM »

Thank you very much! Smiley
Logged
battlezad
Newbie
*
Posts: 44


View Profile
« Reply #3 on: July 17, 2015, 01:36:29 AM »

Is setValue supposed to work like
$('#sbtn').switchbutton('setValue', 'on');
$('#sbtn').switchbutton('setValue', 'off');
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #4 on: July 17, 2015, 07:08:42 PM »

If you wish to set the 'on' and 'off' values on the 'switchbutton' editor, please try the code below:
Code:
<script type="text/javascript">
$.extend($.fn.datagrid.defaults.editors, {
switchbutton:{
init: function(container, options){
var input = $('<input>').appendTo(container);
input.switchbutton(options);
return input;
},
getValue: function(target){
return $(target).switchbutton('options').checked ? 'on' : 'off';
},
setValue: function(target, value){
$(target).switchbutton(value=='on'?'check':'uncheck');
},
resize: function(target, width){
$(target).switchbutton('resize', {width: width,height:22});
}
}
})
</script>
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!