Question

My jqGrid work dynamically.So that all options are loaded dynamically too. This options are generated with java Map<String,Object> All options work very well, but the function name within de map/opts not work. This is json map generated with java.

"colModel":[...{"formatter":"myFunction","index":"","name":""}]

I did not debug the jqgrid.src.js yet and i think that the problem are with the eval. the "myFunction" is not called and the undefined is returned.

Was it helpful?

Solution

The formatter option can be a string if it is one of the predefined formatters, but according to the jqGrid docs for custom formatters:

You can define your own formatter for a particular column. Usually this is a function.

So jqGrid expects a function to be passed. This is why myFunction works but "myFunction" does not. Anyway, to solve your problem you need to output the code:

"formatter": myFunction


To go a bit deeper, you can see in the jqGrid source file grid.base.js that the formatter uses a function directly, but if a string is passed that string is passed to $.fn.fmatter:

    formatter = function (rowId, cellval , colpos, rwdat, _act){
        var cm = ts.p.colModel[colpos],v;
        if(typeof cm.formatter !== 'undefined') {
            var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
            if($.isFunction( cm.formatter ) ) {
                v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
            } else if($.fmatter){
                v = $.fn.fmatter(cm.formatter, cellval,opts, rwdat, _act);
            } else {
                v = cellVal(cellval);
            }
        } else {
            v = cellVal(cellval);
        }
        return v;
    },

If that function is not already present in jquery.fmatter.js then I would expect an error to occur when the grid attempts to use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top