jqGrid tree nodes are read from server using json data. Click in node reads child nodes from server. Code below is used to restore opened tree node if page is loaded. Only single node is opened always in tree. Controller assings node ids to autoClicked array and gridComplete opens nodes using this path. This causes grid flasinging on page load since multiple server requests buid grid multiple times. How to disable grid flashing ? Is it possible to prevent multiple jqGrid building and show only find jqGrid tree ?
Answer in Send expanded TreeGrid Nodes in cookie works for fully populated grid only.
var autoClicked=[<%= Model.Path() %>];
$(function () {
var grid = $("#tree-grid");
grid.jqGrid({
gridComplete: function () {
setTimeout(function () {
var id = autoClicked.shift();
var rData = grid.getGridParam('data');
var data = null;
for (var i = 0; i < rData.length; i++) {
if (id == rData[i].id) {
data = rData[i];
break;
}
}
if (data == null)
return;
grid.expandRow(data);
grid.expandNode(data);
}, 0);
},
url: '<%= ResolveUrl("~/Store/GridData")%>',
datatype: "json",
mtype: "POST",
height: "auto",
loadui: "disable",
treeGridModel: "adjacency",
colModel: [
{ name: "id", width: 1, hidden: true, key: true },
{ name: "menu", classes: "handcursor" },
{ name: "url", width: 1, hidden: true }
],
autowidth: true,
treeGrid: true,
ExpandColumn: "menu",
rowNum: 200,
ExpandColClick: true,
onSelectRow: function (rowid) {
var treedata = grid.jqGrid('getRowData', rowid);
window.location = treedata.url;
}
}
);
});
controller:
public string Path()
{
Artomlii node = Artomliik;
string res = node.Artomaliik.ToString();
while (!Core.IsNullOrWhiteSpace(node.Treeparent))
{
// retrieve parent node
node = MyDataContext.ExecQuery<Artomlii>(@"select * from artomlii where treeorder={0}", node.Treeparent).FirstOrDefault();
if (node == null)
break;
res = node.Artomaliik.ToString() + "," + res;
}
return res;
}