在jqGrid中调用jQuery函数的自定义格式化程序 [英] Custom formatter in jqGrid which calls jQuery function

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

问题描述

我有一个jqGrid与自定义格式化程序,返回两个复选框:

I have a jqGrid with a custom formatter that returns two checkboxes:

jQuery(function($){
    $("#gridAgenda").jqGrid({
    ...
    colModel: [
        ...,
        "asiste",
        ...
    ],
    colModel:[
        ...,  
        {name:'asiste',formatter:asisteFormater},
        ...
    ]
    ...
});
}
function asisteFormater (cellvalue, options, rowObject) {
    return "Sí<input type='checkbox' id='asisteSi'/> No<input type='checkbox' id='asisteNo'/>";
}

$("#asisteSi").click(function () {
    ...
}

但是我想调用一个jQuery函数这两个复选框被选中,以评估哪一个被检查和调用一个ajax函数我认为问题是,asisteSi不存在,直到jqGrid创建,所以我不能这样做。

But I want to call a jQuery function when any of the two checkboxes are checked, to evaluate which one was checked and calling an ajax function. I think the problem is, that asisteSi does not exist until the jqGrid is created, so I cannot do this.

有人可以帮助我吗?

推荐答案

您应该将回调附件放入 gridComplete 选项的网格定义,如下:

You should put the callback attachment into the gridComplete option of the grid definition, just like this:

$('#gridAgenda').jqGrid({
    ...
    gridComplete: function () {
        $("#asisteSi").click(function () {
            // do your deed
        });
    }
});

补充

顺便说一下,如果网格中有多行,则不应使用 asisteSi 作为您的id,因为它在页面中不是唯一的,导致未定义的行为。

By the way, if there are multiple rows in the grid, you should not use asisteSi as your id, because it won't be unique in the page, and that causes undefined behaviour.

这篇关于在jqGrid中调用jQuery函数的自定义格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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