【问题标题】:jqGrid local filtering causing rowid to be set to nulljqGrid本地过滤导致rowid设置为null
【发布时间】:2015-06-22 00:50:58
【问题描述】:

基于jqGrid Filtering Records解决方案,我在本地实现了过滤。

但是我无法将第一行设置为选中。看起来行 ID 已设置为空。我不确定为什么会发生这种情况。

代码如下

$("#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}]);            
});

这是我的 gridComplete 方法,我也尝试过 loadComplete 方法

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

这是我的网格选项:

    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 */
        }

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    要在每次重新加载网格时选择第一行,您需要执行以下操作

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

    我强烈建议您另外在网格中包含gridview: true 选项(有关详细信息,请参阅the answer)并将gridComplete 替换为rowattr 的用法(请参阅the answer)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      相关资源
      最近更新 更多