EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: battlezad on July 16, 2015, 12:16:04 AM



Title: Datagrid switchbutton editor
Post by: battlezad on July 16, 2015, 12:16:04 AM
Hi,
is it possible to extend datagrid editors with switchbutton?

Thanks in advance,
btz


Title: Re: Datagrid switchbutton editor
Post by: jarry 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>


Title: Re: Datagrid switchbutton editor
Post by: battlezad on July 16, 2015, 01:52:08 AM
Thank you very much! :)


Title: Re: Datagrid switchbutton editor
Post by: battlezad on July 17, 2015, 01:36:29 AM
Is setValue supposed to work like
$('#sbtn').switchbutton('setValue', 'on');
$('#sbtn').switchbutton('setValue', 'off');


Title: Re: Datagrid switchbutton editor
Post by: jarry 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>