0

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! )

user3763117
  • 327
  • 1
  • 5
  • 18

1 Answers1

0

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 code or this one as examples of registration of formatters.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @user3763117: By the way I posted recently [the pull request](https://github.com/tonytomov/jqGrid/pull/631) which is merged to the main code of jqGrid on the github. So one can defines column `template` in the same way as strings in the next version of jqGrid. If you still not use column templates I would recommend you to read [the old answer](http://stackoverflow.com/a/6047856/315935). Templates are more powerful as just formatter. It allows to define *multiple* column properties which are specifif for some type of data. – Oleg Sep 13 '14 at 13:22
  • This might be a very interesting approach as we use many different type of formats and plugins. Thank you once again for this information. – user3763117 Sep 13 '14 at 16:10