单击jqgrid单元格时使用参数调用函数 [英] Calling a function with parameter on click of a jqgrid cell

查看:122
本文介绍了单击jqgrid单元格时使用参数调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使一个满足特定条件的单元格变为彩色并可以单击. 我遇到的问题是将参数传递给元素的onclick. 我正在做类似的事情:

I am trying to make a cell colored and clickable if it satisfies certain condition. The problem that I am getting is in passing the parameter to the onclick of the element. I am doing something like:

{
    name: 'numberOfUnits',
    index: 'numberOfUnits',
    sorttype: 'integer',
    cellattr: function (rowId, tv, rawObject, cm, rdata) {
        if (...) {
            return 'style="background-color:red" onClick="javascript:showReceivedLockedPieChartDialog(' + '\'' + lockedCellId + '\'' + ')"';
        }
        else {
            return 'style="color:black"';
        }
    }
}

我看到文字的格式为:

style="background-color:red" onClick="javascript:showReceivedLockedPieChartDialog('ABC')"

我看到它正在创建类似这样的东西...

I see that it is creating something like this...

<td aria-describedby="reportGrid_numberOfUnits" title="13" ABC")"="" onclick="javascript:showReceivedLockedPieChartDialog(" style="background-color:red" role="gridcell">13</td>

请帮助我将参数传递给此函数.

Please help me pass the parameter to this function.

推荐答案

哦,是的!您的代码显示,从cellattr返回的字符串的分离将不会足够仔细地进行解析.我发现最好改写 formatCol ,将在内部使用.我想在下一次发布给trirand建议,以便使用RegEx匹配来更改代码.

Ohh yes! Your code shows that the parting of string returned from cellattr will be parsed not carefully enough. I find that one should better rewrite the function formatCol which will be used internally. I wanted to post next time to trirand suggestion to change the code using RegEx matching.

尽管如此,有一些简单的规则可以允许在当前实现中使用cellattr:

Nevertheless there are some simple rules which could allow to use cellattr in the current implementation:

  • 您应该在cellattr
  • 返回的字符串中使用style属性作为最后一个属性
  • 如果您不仅返回style属性的值,还应该添加其他' '空白作为返回值的第一个字符.
  • 您不应仅将单词styletitleclass用作相应属性的名称.
  • you should use style attribute as the last attribute in the string returned from cellattr
  • you should include additional ' ' blank as the first character of returned value if you returns not only the value for the style attribute.
  • you should not use words style, title and class only as the names of the corresponding attributes.

最后一条规则意味着您不应使用class="mytitle"title="my class style".返回的字符串的解析不是很仔细.因此,此类名称会有一些副作用.正如我在解析结果的代码jqGrid的相应部分之前所写的那样,我认为应该更改.下次,我将尝试将相应的建议发布给trirand.

The last rule means that you should not use class="mytitle" or title="my class style". The parsing of the returned string is not so careful. So such names will have some side effects. As I wrote before the corresponding part of the code jqGrid which parse the results should be changed in my opinion. I will try to post the corresponding suggestions to trirand in the next time.

在您的情况下,您应该将cellattr的代码重写为

In your case you should rewrite the code of cellattr to

cellattr: function (rowId, tv, rawObject, cm, rdata) {
    if (...) {
        return ' onclick="showReceivedLockedPieChartDialog(' + '\'' +
            lockedCellId + '\'' + ')" style="background-color:red"';
    } else {
        return 'style="color:black"';
    }
}

演示显示所做的更改有效.

The demo shows that the changes works.

这篇关于单击jqgrid单元格时使用参数调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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