如何具有自定义格式化程序内置函数来调用非jqGrid单独函数? [英] How to have custom formatter built-in function to call a non-jqGrid seperate function?

查看:59
本文介绍了如何具有自定义格式化程序内置函数来调用非jqGrid单独函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何让jqGrid自定义格式化程序调用单独的函数"test1"?我在"test1"功能上收到未定义的错误.

I'm wondering how to have jqGrid custom formatter to call a seperate function, "test1"? I get an undefined error on the "test1" function.

脚本#1 ...

//colModel json objects...
{ name: 'Vin', index: 'Vin' },
{ name: 'Links', index: 'Links', formatter: jqgridCellFormatterLink }

//jqGrid formatter function...
function jqgridCellFormatterLink(cellValue, options, rowObject) {
    return "<span onclick='test1(\"" + rowObject[0] + "\");'>Test</span>";
}

//non-jqGrid function
function test1(parmVin) {
    alert(parmVin);
}

谢谢...

//脚本#2 ...

//Script #2...

//colModel json objects...
{ name: 'Vin', index: 'Vin' },
{ name: 'Links', index: 'Links', formatter: function(cellValue,options,rowObject) { return "<span>Test</span>";} }

beforeSelectedRow: function(rowid, e) {
   if (this.p.colModel[$.jgrid.getCellIndex($(e.target).closest("td")[0])].name === 'Links') 
   {
       alert($('#blah').getCell(rowid, 0));  //Can be 0 or 'Vin'...
   } 
}

推荐答案

我建议您使用答案中描述的方法>和中.您不需要将onclick绑定到某些 global 方法.与其相反,使用beforeSelectRowonCellSelect回调将更有效,该回调将在一个现有的 click事件句柄内部被调用.

I recommend you to use approach described in the answer and in this one. You don't need to bind onclick to some global method. Instead of that it's more effective to use beforeSelectRow or onCellSelect callback which will be called inside of one existing click event handle.

顺便说一句,您发布的格式化程序可能不起作用,因为rowObject的格式取决于很多事情:如何填充网格,使用的datatype("local""json"或不论您使用repeatitems: true还是jsonReader的某些其他设置,无论是否使用loadonce"xml"都可以生成不同格式的rowObject).

By the way, the formatter which you posted could don't work because the format of rowObject depend on many things: how you fill the grid, which datatype you use ("local", "json" or "xml" can produce different format of rowObject), whether you use repeatitems: true or some other settings of jsonReader, whether you use loadonce or not and so on.

这篇关于如何具有自定义格式化程序内置函数来调用非jqGrid单独函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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