JqG​​rid colModel动态格式化程序 [英] JqGrid colModel dynamic formatter

查看:95
本文介绍了JqG​​rid colModel动态格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jqGrid是动态工作的,因此所有选项也都可以动态加载. 此选项是使用Java Map<String,Object>生成的 所有选项都可以很好地工作,但是de map/opts中的函数名称不起作用. 这是用Java生成的json映射.

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":""}]

我还没有调试jqgrid.src.js,并且我认为问题出在eval上. 不会调用"myFunction",并且返回undefined.

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.

推荐答案

如果formatter选项是预定义的格式化程序之一,则可以是字符串,但是根据

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.

因此jqGrid希望传递一个函数.这就是为什么myFunction有效但"myFunction"无效的原因.无论如何,要解决您的问题,您需要输出代码:

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


要更深入一点,您可以在jqGrid源文件中看到
grid .base.js 表示格式化程序直接使用函数,但是如果传递了一个字符串,则该字符串将传递给$.fn.fmatter:


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;
    },

如果该功能尚未出现在 jquery.fmatter中. js ,那么当网格尝试使用它时,我会期望发生错误.

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.

这篇关于JqG​​rid colModel动态格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆