1

Based on jqGrid Filtering Records solution, i implemented the filtering on local.

However i am unable to set the first row as selected.Looks the row ids have been set to null. I am not sure why this would happening.

Code is as below

$("#showMatchingRecords").click(function(e) {             
    e.preventDefault();               
    var grid = $("#WorkList"), filter,searchfiler;
    searchfiler = "700677";
    grid[0].p.search = true;
    filter = { groupOp:'OR', rules: [] };
    filter.rules.push({field:"Id",op:"eq",data:searchfiler});
    $.extend(grid[0].p.postData, {filters:JSON.stringify(filter)});
    grid.trigger("reloadGrid", [{page:1}]);
   });

$("#showAllRecords").click(function(e) {
     e.preventDefault();
    var grid = $("#WorkList");
    grid[0].p.search = false;
    $.extend(grid[0].p.postData, { filters: "" });
    grid.trigger("reloadGrid", [{page:1}]);            
});

Here is my gridComplete method, I have tried the same with loadComplete as well

       gridComplete : function() {
            $("tr.jqgrow:odd").css("background", "#DDDDDC");
            var grid = $("#WorkList");

            var ids = grid.getDataIDs();

            console.log('before ids....', ids);

            for (var i = 0; i < ids.length; i++) {
                grid.setRowData(ids[i], false, { height: 35 });
            }

Here are my grid options:

    caption: 'Records List',
    width: 1000,
    height: 200,
    pager: $("#WorkListPager"),
    rowNum: 50,
    sortname: 'Name',
    loadonce: true,
    sortorder: "asc",
    cellEdit: false,
    viewrecords: true,
    imgpath: '/Content/Themes/Redmond/Images',
    autowidth: false,
    onSelectRow: function (rowid, status, e) {
     /* function */
        }
Community
  • 1
  • 1
Masood Alam
  • 645
  • 2
  • 8
  • 22

1 Answers1

0

To select the first row on every reload of the grid you need do the following

loadComplete: function () {
    var $self = $(this);
    if (this.rows.length > 1) { // test that grid is not empty
        $self.jqGrid("setSelection", this.rows[1].id);
    }
}

I strictly recommend you additionally to include gridview: true option (see the answer for details) in the grid and to replace gridComplete to the usage of rowattr (see the answer).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798