JqGrid PHP: highlight results, when filtering via toolbar
Asked Answered
L

1

0

I would like to highlight the search results, when using the filter toolbar.

I tried to use the solution Oleg and Abhishek Simon provided here, but it is not working in JqSuite for PHP.

grid.php code snippet

$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);

I get this error:

Notice: Undefined variable: this

Are you able to get what I am doing wrong?

Luiseluiza answered 3/2, 2014 at 8:31 Comment(0)
Y
1

I don't use PHP myself. Anyway you should know the ID of the grid which you use on the page. If it is for example id="grid" then you can replace this with $("#grid")[0] inside of the code of the function.

Yahairayahata answered 3/2, 2014 at 9:18 Comment(6)
I am sorry, but it is still not working. I changed it to: $this = $("#grid")[0]Luiseluiza
@JessStone: The code which you use contains many references to this. The code $this = $(this) can be replaced to $this = $($("#grid")[0]) or just to $this = $("#grid"), The code $('>tbody>tr.jqgrow>td:nth-child('..., this) contains this, the code this.p.search, this.p.postData.filters can be replaced to $("#grid")[0].p.search and $("#grid")[0].p.postData.filters.Yahairayahata
thank you dear @Oleg. unfortunately I am now getting: Uncaught ReferenceError: getColumnIndexByName is not defined Luiseluiza
@JessStone: The code of the demo includes the definition of getColumnIndexByName too. You can just include the code inside of function which you define as $highlighting. The local function getColumnIndexByName can be defined in the same way like any local variable.Yahairayahata
yeah @Yahairayahata you're right! I was missing that function. NB: i have added the function getColumnIndexByName through $grid->setJSCode($custom);, since it wasn't working if added through: $grid->setGridEvent('loadComplete',$highlighting); . so basically my code got split into two sections :) thanks once again my Guru!Luiseluiza
how can I avoid highlighting results even in the edit and form-view form? i tried to add :not(\'.form-view-data\') (exclude form view class) to the code : $('>tbody>tr.jqgrow>td:not(\'.form-view-data\'):nth-child(' + (iCol + 1) +')', $('#grid')[0]).highlight(rule.data); . Though, it is not working!Luiseluiza

© 2022 - 2024 — McMap. All rights reserved.