Author Topic: Search for multiple words in multiple columns + yellowmark matches  (Read 19876 times)

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Search for multiple words in multiple columns + yellowmark matches
« Reply #15 on: February 24, 2014, 10:09:08 pm »
If you want to maintain the natural order of the records (without any apparent sorting)

1) keep a hidden column of unique values (may be primary key or numeric values 1,2,3, etc)
2) set the initial sortIndx equal to dataIndx of that hidden column.

« Last Edit: February 24, 2014, 10:33:06 pm by paramquery »

motoguru

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Search for multiple words in multiple columns + yellowmark matches
« Reply #16 on: February 25, 2014, 12:22:09 am »
Got it, thanks :)

motoguru

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Search for multiple words in multiple columns + yellowmark matches
« Reply #17 on: February 27, 2014, 07:56:42 pm »
Hello there, 2.0.4..

Ok then, I get:

TypeError: cd.indexOf is not a function

if (cd.indexOf(value) != -1) {

pqgrid.dev.js (row 9339)



In

function filterhandler(evt, ui) {

            var $toolbar = $grid.find('.pq-toolbar-search'),
                $value = $toolbar.find(".filterValue"),
                value = $value.val(),
                condition = $toolbar.find(".filterCondition").val(),
                dataIndx = $toolbar.find(".filterColumn").val(),
                filterObject;

            var word = value;
            if (condition == 'regexp') {
                var spl = word.split(" ");
                word = "";
                for (var n in spl) {
                    word += spl[ n ];
                    if (n != spl.length - 1) {
                        word += "|";
                    }
                }
                word = new RegExp(word);
                value = word;
            }

            if (dataIndx == "") {//search through all fields when no field selected.
                filterObject = [];
                var CM = $grid.pqGrid("getColModel");
                for (var i = 0, len = CM.length; i < len; i++) {
                    var dataIndx = CM[ i ].dataIndx;
                    filterObject.push({ dataIndx: dataIndx, condition: condition, value: value });
                }
            }
            else {//search through selected field.
                filterObject = [{ dataIndx: dataIndx, condition: condition, value: value }];
            }
            $grid.pqGrid("filter", {
                oper: 'replace',
                data: filterObject
            });
        }


when using condition "regex". You said my code logic is good before, so any suggestions?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Search for multiple words in multiple columns + yellowmark matches
« Reply #18 on: February 27, 2014, 08:57:44 pm »
Could you try to pass word as it is instead of creating a new RegExp.

motoguru

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Search for multiple words in multiple columns + yellowmark matches
« Reply #19 on: February 28, 2014, 03:52:10 pm »
This one solved the problem, thank You. [EDIT: contain criteria didn't work because I had problem with filterrender funcition]

If somebody is interested in having regexp hightlited, this is the example of altered filterrender function:

//filterRender to highlight matching cell text.
function filterRender(ui) {
 
    var val = ui.cellData,
        filter = ui.column.filter;

    var valTest = safeToString(val);
    if (valTest.indexOf("<a") != -1 || valTest.indexOf("<img") != -1) {
        return val;
    }

    if (filter && filter.on && filter.value) {
        var condition = filter.condition,
            valUpper = safeToString(val).toUpperCase(),
            txt = filter.value,
            txtUpper = txt.toUpperCase(),
            indx = -1;
        if (condition == "end") {
            indx = valUpper.lastIndexOf(txtUpper);
            //if not at the end
            if (indx + txtUpper.length != valUpper.length) {
                indx = -1;
            }
        }
        else if (condition == "contain") {
            indx = valUpper.indexOf(txtUpper);
        }
        else if (condition == "begin") {
            indx = valUpper.indexOf(txtUpper);
            //if not at the beginning.
            if (indx > 0) {
                indx = -1;
            }
        }
        else if (condition == "regexp") {
            txt = txt.replace("/").split("|");
            val = safeToString(val);
            for (var n in txt) {
                var txtNoRegexp = txt[n];
                txt[n] = new RegExp(txt[n],"ig");
                val = val.replace(txt[n], "<span style='background:yellow;color:#333;'>" + txtNoRegexp + "</span>");
            }
            return val;
        }
        if (indx >= 0) {
            var txt1 = val.substring(0, indx);
            var txt2 = val.substring(indx, indx + txt.length);
            var txt3 = val.substring(indx + txt.length);
            return txt1 + "<span style='background:yellow;color:#333;'>" + txt2 + "</span>" + txt3;
        }
        else {
            return val;
        }
    }
    else {
        return val;
    }
}


safeToString() is the method mentioned above ITT.
« Last Edit: February 28, 2014, 06:46:03 pm by motoguru »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Search for multiple words in multiple columns + yellowmark matches
« Reply #20 on: February 28, 2014, 09:27:39 pm »
Thanks for sharing.