EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: huyannet on June 16, 2016, 01:37:19 AM



Title: How to use switchbutton in PropertyGrid?
Post by: huyannet on June 16, 2016, 01:37:19 AM
I use only two value properties as 'true' & 'false'. How to do that?
My code:
rows = [
   {field:"a",name:"jeasyui",value:"true",group:"Libraries", editor:{
        type:"switchbutton", options: {
               valueField: "value",
               textField: "label",
               editable: false,
               data: test
            }
        }
        },

][/font]


Title: Re: How to use switchbutton in PropertyGrid?
Post by: stworthy on June 16, 2016, 06:28:48 PM
You have to extend the 'switchbutton' editor before using it.
Code:
<script>
$.extend($.fn.datagrid.defaults.editors, {
switchbutton:{
init:function(container,options){
var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);
return input.switchbutton(options);
},
getValue:function(target){
return $(target).switchbutton('options').checked;
},
setValue:function(target,value){
if (value){
$(target).switchbutton('check');
} else {
$(target).switchbutton('uncheck');
}
},
resize: function(target, width){
$(target).switchbutton('resize', {width:width});
}
}
});
</script>

Usage example:
Code:
{"name":"FrequentBuyer","value":false,"group":"Marketing Settings","editor":{
"type":"switchbutton",
"options":{
}
}}


Title: Re: How to use switchbutton in PropertyGrid?
Post by: huyannet on June 20, 2016, 12:41:06 AM
I change $.fn.datagrid.defaults.editors to $.fn.propertygrid.defaults.editors and it work perfect !!
Thanks for the support !