如何使用自定义格式化器内置函数来调用非jqgrid独立函数

How to have custom formatter built-in function to call a non-jqGrid seperate function?

本文关键字:函数 调用 jqgrid 独立 内置 何使用 自定义 格式化      更新时间:2023-09-26

我想知道如何有jqGrid自定义格式化程序调用一个单独的函数,"test1"?我在"test1"函数上得到一个未定义的错误。

脚本# 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…

//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绑定到某个全局方法。相反,使用beforeSelectRowonCellSelect回调更有效,它们将在内部调用一个现有的 click事件句柄。

顺便说一下,你发布的格式化器可能不起作用,因为rowObject的格式取决于很多事情:你如何填充网格,你使用的datatype ("local", "json""xml"可以产生不同的rowObject格式),你是否使用repeatitems: truejsonReader的其他一些设置,是否使用loadonce等等。