In continue of this topic I want to save expanded nodes in cookie. Is it the best way?
I'm not sure in way of JSON data checking.
Why expandRow doesn't work?
var gridId = "#table";
var grid = $(gridId);
grid.jqGrid({
...
loadComplete: function() {
var ids = grid.jqGrid('getDataIDs');
var cookie = $.cookie(gridId + '_expanded');
var expanded = false;
if (typeof(cookie) == 'string')
var expanded = JSON.parse(cookie);
for (var i=0;i<ids.length;i++) {
var id=ids[i];
var row_data = $(this).jqGrid('getRowData', id);
if (expanded && id in expanded && expanded[id] == 'true')
$(gridId + ' tr#' + id + ' div.treeclick').trigger("click");
//Why it doesn't work?
//grid.jqGrid('expandRow', row_data);
}
}
...
});
function setCookie() {
var ids = grid.jqGrid('getDataIDs');
var expanded = Object();
var string = '';
for (var i=0;i<ids.length;i++) {
var id=ids[i];
var rowData = grid.jqGrid('getRowData', id);
if (rowData.parent != '' && grid.jqGrid('isVisibleNode', rowData) === true)
expanded[rowData.parent] = true
}
for (e in expanded)
string += '"' + e + '":' + '"' + expanded[e] + '",';
$.cookie(gridId + '_expanded', '{'+ string.substring(0, string.length - 1) + '}', { expires: 365 });
}
var orgExpandNode = $.fn.jqGrid.expandNode, orgCollapseNode = $.fn.jqGrid.collapseNode;
$.jgrid.extend({
expandNode : function(rc) {
orgExpandNode.call(this, rc);
setCookie();
},
collapseNode : function(rc) {
orgCollapseNode.call(this, rc);
setCookie();
},
});
P.S. I allways get this stupid alert :)
Your post does not have much context to explain the code sections; please explain your scenario more clearly.