3

I have a grid in which I am providing search when the user highlights the text they want to filter.

The onCellSelect looks like this:

onCellSelect: function(row, col, content, event) {
    var cm = grid.jqGrid("getGridParam", "colModel");
    if (window.getSelection) {
        selection = window.getSelection();
    } else if (document.selection) {
        selection = document.selection.createRange();
    }
    selectionColumn = cm[col].name;
    selection.toString() !== '' && $("#gs_"+selectionColumn).val(selection.toString());
    console.log($("a.soptclass[data-colname='"+selectionColumn+"']").attr('data-soper'));
    if(selection.toString() != '')
    {
        grid[0].triggerToolbar();
    }

}

Now I have some search operators which I have customized and using it in the grid:

searchoptions:{sopt:["cn",'mc','mn',"eq","ne","lt","le","gt","ge","bw","ew","nc"]}

The mc and mn are a part of customSortOperations.

Now what I want is when the user selects some text inside a specific cell inside a grid, I want to detect which search filter was used. For example by default the search filter is cn.

I have tried this:

$("a.soptclass[data-colname='"+selectionColumn+"']").attr('data-soper')

but it gives me the default cn everytime.

I can get the text inside the link which will give me a symbolic name like ~ for cn, == for eq with

$("a.soptclass[data-colname='"+selectionColumn+"']").text()

However is there a jqgrid way of rather getting the exact search operator selected? i.e. cn,eq,ne,le, etc

Please let me know if a working demo is required and I will update the question.

UPDATE: DEMO.

On line 659 and 660 I am using this callback $("a.soptclass[data-colname='"+selectionColumn+"']").text()

In other words I want the selected search operator inside onCellSelect

Dipen Shah
  • 1,911
  • 10
  • 29
  • 45
  • I'm not sure that I understand you correctly. Inside of which callback you tried to use expressions like `$("a.soptclass[data-colname='"+selectionColumn+"']").text()`? Could you prepare a some demo with the test case? If I would exactly understand what you want to implement I would help you. – Oleg Apr 06 '16 at 14:42
  • @Oleg I have prepared a demo [here](http://jsfiddle.net/jbksad8e/). Please take a look when you have time. – Dipen Shah Apr 06 '16 at 15:10

1 Answers1

1

I still not full understand what exact behavior you want to implement, but it seems that you can start the onCellSelect code with the following:

onCellSelect: function(row, col, content, event) {
    var p = $(this).jqGrid("getGridParam");
    var hDiv = p.frozenColumns === true && p.colModel[col].frozen === true ?
                this.grid.fhDiv : this.grid.hDiv;
    var $elem = $(hDiv).find("#gs_" + $.jgrid.jqID(p.id + "_" + p.colModel[col].name));
    var oper = $elem.parent().prev().children("a").data("soper");
    ...
}

The $elem uses the standard id behavior of the current free jqGrid implementation (no idMode option of filterToolbar is specified). The element $elem is the <input> or <select> element in the filter toolbar. You can use $elem(selection) to change the value. The oper variable contains the currently chosen searching operation. One should use .data("soper") instead of .attr("data-soper") to access the data.

I hope it's what you are missing currently.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hello @Oleg, this is exactly what I wanted. The purpose of this kind of requirement is that I want to be able to provide them search on selection of text which is happening right now. However I wanted to implement a multiple not contains filter. So for that the user must be able to select the filter first and then select which string they want to exclude. So in order to do that I needed to detect what kind of filter is selected. This works wonderfully. Thank you once again. – Dipen Shah Apr 06 '16 at 18:07
  • @DipenShah: You are welcome! You can try to combine selection with right mouse click, which creates context menu from the searching operation allowed for the column and to force the searching after the used made the choice in the context menu. You can consider to display the same context menu without right mouse click (directly after selection). The user will see the selected word and can directly choose the searching operation. – Oleg Apr 06 '16 at 18:42
  • thank you for your suggestion but this will make the user click 2 times intead of one which is currently happening. Most of the times the user is going to do a normal contains filter which can be done with a single click. But if I provide a context menu or something similar that will add one more click on top of it which I don't want. – Dipen Shah Apr 06 '16 at 19:21
  • 1
    @DipenShah: OK, I understand now. It sound like very helpful feature! – Oleg Apr 06 '16 at 20:15
  • Yes thank you. The objective is to make the users' operation much faster. – Dipen Shah Apr 07 '16 at 01:16