EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: proffl on July 06, 2014, 03:53:27 AM



Title: how to add "formatter" using json?
Post by: proffl on July 06, 2014, 03:53:27 AM
hi, i'm now using properygrid for editing entity,  here is my property json like below:
Code:
string json = "{\"total\":6,\"rows\":[";
            json += "{\"name\":\"id\",\"value\":\""+ID+"\"}";
            json += ",{\"name\":\"name\",\"value\":\"" + Name + "\",\"editor\":\"text\"}";
            json += ",{\"name\":\"path\",\"value\":\"" + Url + "\",\"editor\":\"text\"}";
            json += ",{\"name\":\"icon\",\"value\":\"<span class='icon " + Icon +
                "'>&nbsp;</span>\",\"editor\":{\"type\":\"combobox\",\"options\":{\"valueField\":\"id\",\"textField\":\"name\",\"url\":\"/Icon.aspx\",\"groupField\":\"group\"}}}";
            json += "]}";
and i wanna my icon's editor display icon image. instead of text, so i change editors to :
Code:
\"editor\":{\"type\":\"combobox\",\"options\":{\"valueField\":\"id\",\"textField\":\"name\",\"url\":\"/Icon.aspx\",\"groupField\":\"group\",\"formatter\":\"function(row){brbr}\"}}}";
but it seems javascript take "function(row){brbr}" as string instead of function.
how can i add formatter to the editor ?


Title: Re: how to add "formatter" using json?
Post by: jarry on July 06, 2014, 07:23:08 PM
The 'formatter' must be defined in the columns definitions. Please try this:
Code:
$('#pg').propertygrid({
columns:[[
{field:'name',title:'Name',width:100,sortable:true},
{field:'value',title:'Value',width:100,resizable:false,
        formatter:function(value){
        return value;
        }
}
    ]]
})


Title: Re: how to add "formatter" using json?
Post by: proffl on July 07, 2014, 07:30:21 AM
thanks for the reply.
as i'm using propertygrid, and i just need one of my property's editor using formatter. so i extends the editor and add formatter to it's options then, fix the problem.