【问题标题】:JqGrid PHP: highlight results, when filtering via toolbarJqG​​rid PHP:通过工具栏过滤时突出显示结果
【发布时间】:2014-02-03 08:31:54
【问题描述】:

我想在使用过滤器工具栏时突出显示搜索结果。

我尝试使用OlegAbhishek Simon 提供的here 解决方案, 但它不适用于 JqSuite for PHP。

grid.php 代码 sn-p

$highlighting = <<<HIGHLIGHTING

function () {
    var filters, i, l, rules, rule, iCol, $this = $(this);
    if (this.p.search === true) {
        filters = $.parseJSON(this.p.postData.filters);
        if (filters !== null && typeof filters.rules !== 'undefined' &&
                filters.rules.length > 0) {
            rules = filters.rules;
            l = rules.length;
            for (i = 0; i < l; i++) {
                rule = rules[i];
                iCol = getColumnIndexByName($this, rule.field);
                if (iCol >=0) {
                    $('>tbody>tr.jqgrow>td:nth-child(' + (iCol + 1) +
                        ')', this).highlight(rule.data);
                }
            }
        }
    }
}

HIGHLIGHTING;

$grid->setGridEvent('loadComplete',$highlighting);

我收到此错误:

注意:未定义变量:this

你能理解我做错了什么吗?

【问题讨论】:

    标签: javascript php jqgrid jqgrid-php


    【解决方案1】:

    我自己不使用 PHP。无论如何,您应该知道您在页面上使用的网格的 ID。如果是例如id="grid",那么您可以在函数代码中将this 替换为$("#grid")[0]

    【讨论】:

    • 很抱歉,它仍然无法正常工作。我把它改成了:$this = $("#grid")[0]
    • @JessStone:您使用的代码包含 许多this 的引用。代码$this = $(this)可以替换为$this = $($("#grid")[0])或只替换为$this = $("#grid"),代码$('&gt;tbody&gt;tr.jqgrow&gt;td:nth-child('..., this)包含this,代码this.p.searchthis.p.postData.filters可以替换为$("#grid")[0].p.search$("#grid")[0].p.postData.filters
    • 谢谢你亲爱的@Oleg。不幸的是我现在得到:Uncaught ReferenceError: getColumnIndexByName is not defined
    • @JessStone:the demo的代码中也包含getColumnIndexByName的定义。您可以只包含定义为$highlighting 的函数的代码inside。局部函数getColumnIndexByName可以像任何局部变量一样定义。
    • 是的@Oleg 你是对的!我错过了那个功能。注意:我已经通过$grid-&gt;setJSCode($custom); 添加了函数getColumnIndexByName,因为如果通过$grid-&gt;setGridEvent('loadComplete',$highlighting); 添加它就不起作用。所以基本上我的代码分为两部分:) 再次感谢我的大师!
    猜你喜欢
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    • 2013-03-09
    • 1970-01-01
    相关资源
    最近更新 更多