khAn khAn - 7 months ago 13
Javascript Question

Collapse and expand functionality is not working in jqgrid?

Very first time all expand/expand all and collapse/collapse all functionality works fine, but when I click next time it expand some rows only.

Screen shot

my jquery code:

.navButtonAdd('#pager',{
caption:"Expand All",
id:"expandGridBtn",
buttonicon:"ui-icon-plus",
onClickButton: function(){
var grid = $("#transactionDetailList");
var rows = grid.jqGrid("getDataIDs");
$.each(rows, function(index, rowId) {
grid.expandSubGridRow(rowId);
});
}
}).navButtonAdd('#pager',{
caption:"Collapse All",
id:"collapseGridBtn",
buttonicon:"ui-icon-minus",
onClickButton: function(){
var grid = $("#transactionDetailList");
var rows = grid.jqGrid("getDataIDs");
$.each(rows, function(index, rowId) {
grid.collapseSubGridRow(rowId);
});
}
});


HTML:

<div class="vc_content">
<div class="buttons_cont">
<a href="JavaScript:void('0');" onClick="exportToExcel();" class="button_export" hidden="hidden"></a>
<a href="JavaScript:void('0');" onClick="exportToWord();" hidden="hidden"></a>
<a href="JavaScript:void('0');" onClick="addNewField()" class="button_add_new" hidden="hidden"></a>
<a href="JavaScript:void('0');" onClick="extractionTemplate()" class="button_extr_templ" >Export Template</a>
<div class="clear"></div>
</div>
<table id="transactionDetailList"></table>
<div id="pager"></div>
</div>


jqgrid :

expandSubGridRow : function(rowid) {
return this.each(function () {
var $t = this;
if(!$t.grid && !rowid) {return;}
if($t.p.subGrid===true) {
var rc = $(this).jqGrid("getInd",rowid,true);
if(rc) {
var sgc = $("td.sgcollapsed",rc)[0];
if(sgc) {
console.log(rowid);
$(sgc).trigger("click");
}
}
}
});
},
collapseSubGridRow : function(rowid) {
return this.each(function () {
var $t = this;
if(!$t.grid && !rowid) {return;}
if($t.p.subGrid===true) {
var rc = $(this).jqGrid("getInd",rowid,true);
if(rc) {
var sgc = $("td.sgexpanded",rc)[0];
if(sgc) {
$(sgc).trigger("click");
}
}
}
});
},

Answer

I have figured it out myself, this issue is arise because of insufficient rowNum size in jqgrid.src.js so i increased it to 50 now it starts working.