wcfdynamicfree-jqgridjqgrid-formatter

Apply JQgrid formatoptions in dynamic binding


I am creating JQgrid dynamically using JSON data returned from a WCF service. All the single value attributes like name,editable etc get binded successfully. But I need to apply currency format on the value getting displayed in grid. For this I have set formatter: currency and for adding formatoptions I have used a class with prefix as its member and set its value as '$' . In the output formtoptions appear as "formatoptions":[{"prefix":"$"}] but not able to set on grid. Also tried with simple string text as "formatoptions":"{prefix: $}" but no success.

Complte JSON format of model is:

{\"name\":\"month\",\"editable\":true,\"width\":\"100\",\"formatter\":\"currency\",\"hidden\":false,\"align\":\"right\",\"formatoptions\":\"{prefix: $}\"}]"}

Can you please help in applying formatoptions on JQgrid when creating the columns and column models dynamically using WCF service returning JSON data .

Thanks


Solution

  • Both "formatoptions":"{prefix: $}" and "formatoptions":[{"prefix":"$"}] are wrong. The correct would be the usage of "formatoptions":{"prefix":"$"}.

    UPDATED: Your demo uses wrong data for formatoptions property:

    \"formatoptions\":\"{\\\"prefix\\\":\\\"$\\\"}\"
    

    which corresponds the string '{"prefix":"$"}' instead of

    \"formatoptions\":{\"prefix\":\"$\"}
    

    which corresponds the object {"prefix":"$"}

    Fixing of the data solves the problem. See https://jsfiddle.net/oyavoe00/1/