JqGrid select particular row which may or may not be visible

主宰稳场 提交于 2019-12-05 19:22:26

You can try just to add call setSelection method inside of loadComplete of the $("#studentGrid") grid:

loadComplete: function () {
    $(this).jqGrid("setSelection", myId, true);
}

If the row with the id equal to myId in not on the current page then no rows will be selected. If the row with id = myId is do on the current page then the row will be selected. Is it what you want?

Justin Ethier

You can only select a row that is on the current page.

You could store the selected rows in an array (or some other data structure) and select any "selected" rows when you change pages - this answer should help: jqGrid: How to use multiselect on different pages

Alternatively you could do what you suggest and only display that one row, depending upon your requirements.

I'm just guessing here -

  1. If you already have the id's for what needs to be selected why not keep it in memory? Or perhaps cookies or HTML5 locaStorage?

  2. Then use those values to set a selected row as and when the concerned rows appear in the current page.

  3. You can always serialize your "selected id's" back and forth between page requests (if not using ajax)

Faiyet

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

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});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!