JqG​​rid选择可能可见或不可见

JqG​​rid选择可能可见或不可见

本文介绍了JqG​​rid选择可能可见或不可见的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jqGrid,有几页项目.我有一行ID,该ID可能在第一页上,也可能埋在其他页面的某处.

I have a jqGrid and there are several pages of items. I have the Id of a row which may be on page one or may be buried in the other pages somewhere.

鉴于该行的ID,如何以编程方式选择该行?我正在使用按钮的click事件,如下所示:

Given the ID of the row, How do I programmatically select such a row ? I am using the click event of a button as follows

.on("click", function(){
     var myId = $(this).attr("id");
     $("#studentGrid").jqGrid.setSelection(myId, true);
});

当我单击按钮时,将显示以下Firebug控制台.

When I click on the button I get the following th the firebug console.

TypeError:this.each不是一个函数

有什么想法吗?

编辑
因此,我选择仅用一条记录重新填充网格.问题是我没有使用本地数据.我的dataType是"json".像这样

EDIT
So I opted to repopulate the grid with just one record. The thing is I am not using local data. My dataType is "json". Like this

  $("#studentGrid").jqGrid({
                url: '<c:url value="/students/studentjsondata"/>',
                datatype: 'json',
                height: 'auto',
                colNames:['id','First Name', 'Last Name', 'Other Name' ,'Date Of Birth', 'Gender'],
                colModel:[
                        //Bla Bla Bla
                ],
                rowNum:10,
                autowidth: true,
                pager: '#pager',
                sortname: 'id',
                viewrecords: true,
                sortorder: "desc",
                caption:"Students",
                emptyrecords: "Empty Records",
                subGrid: true,
                /* <![CDATA[ */
                onSelectRow: function(id){
                    if((lastsel != 0)&&(id!==lastsel)){
                        $("#studentGrid").jqGrid('collapseSubGridRow', lastsel);
                    }
                    lastsel=id;
                }/* ]]> */ ,
                subGridOptions: {
                    "plusicon" : "ui-icon-triangle-1-e",
                    "minusicon" : "ui-icon-triangle-1-s",
                    "openicon" : "ui-icon-arrowreturn-1-e",
                    "reloadOnExpand" : true,
                    "selectOnExpand" : true
                },
                subGridRowExpanded: function(subgrid_id, row_id) {
                    //Bla Bla Bla
                }
    });

我有想要重新填充网格的json字符串.如何使用此新数据重新初始化网格.我下面的json字符串具有相应的逻辑,如下所示,但是什么也没发生.

I have the json string I want to repopulate the grid with. How do I re-initialize the grid with this new data. I the following json string with the corresponding logic as follows, but nothing happens.

{'page':'1', 'records':'1', 'total':'1', 'rows':[{'id':'7385', 'cell': ['Max', 'Payne', '', 'September 16, 2012', 'Male']}]}


.on("click", function(){
  var myNewData = eval('(' + $(this).attr("griddata") + ')');
  $("#studentGrid").jqGrid('setGridParam', { datatype: 'local', data: myNewData}).trigger('reloadGrid');
 });

推荐答案

所以,谢谢大家的评论.他们引导我找到了这个答案.此链接也非常有用.因此,这是使用json字符串更新非本地数据的代码.

So guys, thank you all for the comments. They guided me to this answer. This link was quite helpful as well. So this is the code for updating non local data using a json string.

.on("click", function(){
    $("#studentGrid").jqGrid('setGridParam', { jsonReader: { repeatitems: false }, datatype: 'jsonstring', datastr: $(this).attr("griddata")}).trigger('reloadGrid');
});

希望它可以帮助其他人.现在,我要做的就是找出如何通过删除这些限制因素来正确地重新加载网格的方法.这是通过使用默认的jsonReader如下实现的.

Hope it helps someone oth there. Now all I have to do is figure out how to reload the grid properly by removing these paramiters. This is accomplished by using the default jsonReader as follows.

$("#studentGrid").jqGrid('setGridParam', {    jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true,
cell: "cell",
id: "id",
userdata: "userdata",
subgrid: {root:"rows",
repeatitems: true,
cell:"cell"
 }
} , datatype: 'json', datastr: null});

这篇关于JqG​​rid选择可能可见或不可见的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:23