简体   繁体   中英

Remove from JSON double quote for jqGrid formatter

I generate the colModel out of my JSON response from the webservice and this data is directly bounded to the colModel, which works perfect.

The problem I have is to remove somehow or make jqGrid understand that the value in "formatter" is a function, I do know jqGrid expect it to be without double quotes, but I have no idea how to remove the double quotes from the JSON so when I load the JSON to the colModel the function is actually called. With the double quotes it does not work. I have looked for a day everywhere and can't find the solution on this (or remove the double qoutes or make jqGrid understand the value in formatter is a function to call.

Currently I have:

 {"editable":true,"edittype":"checkbox","index":"invite","jsonmap":"invite","key":false,"name":"invite","label":"Invite","formatter":**"myfunction"**,"resizable":true,"hidden":false,"search":false,"sortable":true,"width":50,"sorttype":0,"align":"left"},

Need to have:

 {"editable":true,"edittype":"checkbox","index":"invite","jsonmap":"invite","key":false,"name":"invite","label":"Invite","formatter":**myfunction**,"resizable":true,"hidden":false,"search":false,"sortable":true,"width":50,"sorttype":0,"align":"left"},

Any help in this would be well appriciated! )

JSON don't allows you to reference functions. So you should use strings like "formatter": "myFormatter" . To make such code working you should extend defined myFormatter as method of $.fn.fmatter object:

$.extend($.fn.fmatter, {
    myFormatter: function (cellValue, options) {
        // ...
    }
});

Look at the cod e or this one as examples of registration of formatters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM