2013-05-16 25 views
0

我想知道如何让jqGrid自定义格式化程序调用一个单独的函数,“test1”? “test1”函数出现未定义的错误。如何让自定义格式化程序内置函数调用非jqGrid分离函数?

脚本#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'... 
    } 
} 

回答

1

我建议你使用的方法在the answer描述和在this one。您不需要将onclick绑定到某些全局方法。取而代之的是,使用beforeSelectRowonCellSelect回调将更有效,回调将在内调用一个现有的click事件句柄。

顺便说一句,你可以发布不工作,因为rowObject格式取决于许多因素,格式化:你如何填写电网您使用的datatype,("local""json""xml"可生产rowObject不同格式),无论是否使用repeatitems: true或某些其他设置jsonReader,无论是否使用loadonce等。

+0

不错!现在我得到了使用jqGrid beforeSelectRow对象的“test1”函数。现在,我如何将单元格值传递给jqGrid beforeSelectRow对象中的“test1”函数?谢谢。 – fletchsod

+0

@fletchsod:不客气!你现在用哪种方式?代码在哪里?如果你做得正确,你会得到'e'(事件)作为参数。你可以从'e.target'获得**所有需要的信息**。 – Oleg

+0

我刚刚更新了上面的脚本。我把它们写在纸上,然后由于内联网的限制,在特定的计算机上输入。我正在使用数据类型:json。不使用重复项。我正在使用loadonce:true。希望我的描述够好。 – fletchsod

相关问题