Horus
Horus

Reputation: 15

Is it possible to dynamically close or open a Jqgrid column search?

Is it possible to open and close the search function of certain columns after loading Jgrid?

The underlying code allows you to hide the search part, but does not affect the search function

It works fine to hide but I haven't found what I need to do to show it

this code does not affect the search function

I have to influence the search

$("#gs_name").closest(".ui-search-table").hide();

Sample jsfiddle

UPDATE

The desired combination in the Client Name column

search = hidden -> search = false

search = show -> search = true

$("#columnhide").click(function(){
$("#gs_name").val("")
$("#gs_name").closest(".ui-search-table").toggle();
});

Upvotes: 1

Views: 298

Answers (3)

Tony Tomov
Tony Tomov

Reputation: 3277

The hidden property in double click is a property of colModel. In your case you should use the jquery selector :hidden to do the job.

The code can be changed like this:

ondblClickRow: function(rowid, iRow, iCol, e) {
    var cm = $(this).jqGrid("getGridParam", "colModel");
    var cmvalues = $(this).jqGrid("getRowData", rowid);
    $.each(cm, function(i,n){
        if(!n.hidden) {
            var elem = $('#gs_'+n.name);
            if( elem.is(":hidden") {
                // set it to empty to overcome search when trigger
                elem.val("");
            } else {
                elem.val( cmvalues[n.name]);
            }
        }
    });
    this.triggerToolbar();
},

Upvotes: 0

Horus
Horus

Reputation: 15

This code searches its data if the column is clicked

ondblClickRow: function(rowid, iRow, iCol, e) {
        var $grid = $(this),
            cm = $grid.jqGrid("getGridParam", "colModel"),
            cellvalue = $grid.jqGrid("getCell", rowid, iCol),
            $searchField = $("#gs_" + cm[iCol].name);
        if (!$searchField.is(":hidden")) {
            $searchField.val(cellvalue);
            this.triggerToolbar();
        }
    },

All the columns are retrieved

      ondblClickRow: function(rowid, iRow, iCol, e) {
      var grid=$('#grid');
    var cm = $(this).jqGrid("getGridParam", "colModel");
    var cmvalues = $(this).jqGrid("getRowData", rowid);
    $.each(cm, function(i,n){
        if(!n.hidden) {
            $('#gs_'+n.name).val( cmvalues[n.name])
        }
    });
    this.triggerToolbar();
  },    

I could not set the first code according to the second code!

I want all column data to be searched by double clicking

this is important for a practical filter

I want to do a search in all areas by doing double clicking, but I will never search in hidden columns!

Upvotes: 0

Oleg
Oleg

Reputation: 221997

If I correctly understand what you need to implement then http://jsfiddle.net/OlegKi/ejnrtocw/270/ demonstrates what you can do. The code uses

$("#columnhide").click(function(){
    var $searchField = $("#gs_name");
    $searchField.val(""); // clear the filter
    $searchField.closest(".ui-search-table").toggle(); // hide or show the control
    $(this).html("<b>" + ($searchField.is(":hidden") ? "Show" : "Hide") +
                 "</b> Client Name Search");
    $("#grid")[0].triggerToolbar(); // force filtering without a filter in "name" field
});

and additionally modifies the code of `` callback to the following

ondblClickRow: function(rowid, iRow, iCol, e) {
    var $grid = $(this),
        cm = $grid.jqGrid("getGridParam", "colModel"),
        cellvalue = $grid.jqGrid("getCell", rowid, iCol),
        $searchField = $("#gs_" + cm[iCol].name);

    if (!$searchField.is(":hidden")) {
        $searchField.val(cellvalue);
        this.triggerToolbar();
    }
}

Upvotes: 1

Related Questions