I have a grid with subgrids (Grandparent, Parent, child relationship).
Is there a way to set specific rows to expandable/not-expandable based on a condition?
For instance, all Grandparents have children (parents), and some Parents have children and others don't. Is there a way to make these Parents without children not be expandable in jqgrid? I was looking at the onSubgridBeforeExpand attribute, but that will just prevent the subgrid from expanding. I do not wish to confuse users into thinking that the grid should be expandable when in reality it is not (Clicking the plus button and then nothing happening would be confusing imo). Worst case scenario I can use this attribute to display something that states there are no children, but I would like to avoid that if possible.
Thanks in advance, and here is my jsp with the grid in it. I do not believe the struts.xml or action classes are necessary for this type of question, but if you provide a reason why they might be required I can share them.
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
<s:form id="getJunctionInstance" name="getJunctionInstance" action="populateJI" targets="#gridtable" method="post">
<input hidden="true" name="rpName" id="rpName"/>
</s:form>
<s:form id="getServerHealth" name="getServerHealth" action="populateSH" targets="#gridtable2" method="post">
<input hidden="true" name="jiName" id="jiName"/>
</s:form>
<script>
$.subscribe("getJunctionInstance",function(event){
let row_id = event.originalEvent.row_id;
document.forms['getJunctionInstance'].elements['rpName'].value = row_id;
//document.forms['getJunctionInstance'].submit();
//Don't submit the form, as it is submitted when onSubGridRowExpanded for gridtable is called
});
$.subscribe("getServerHealth",function(event) {
let row_id = event.originalEvent.row_id;
document.forms['getServerHealth'].elements['jiName'].value = row_id;
});
</script>
<s:url var="remoteurl" action="updateRP"/>
<s:url var="junctionInstanceJson" action="updateJIJson"/>
<s:url var="serverHealthJson" action="updateSHJson"/>
<sjg:grid
id="gridtable"
caption="Reverse Proxy List"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="proxies"
rowList="10,15,20"
rowNum="20"
rownumbers="true"
onSubGridRowExpanded="getJunctionInstance"
height="600"
width="900"
loadonce="true"
>
<sjg:grid
id="gridtable2"
caption="Junction Instance List"
dataType="json"
subGridUrl="%{junctionInstanceJson}"
pager="true"
gridModel="junctionInstance"
formIds="getJunctionInstance"
reloadTopics="getJunctionInstance"
rowList="10,15,20"
rowNum="20"
rownumbers="false"
onSubGridRowExpanded="getServerHealth"
width="700"
loadonce="true"
>
<sjg:grid
id="gridtable3"
caption="Server Health List"
dataType="json"
subGridUrl="%{serverHealthJson}"
pager="true"
gridModel="serverInstance"
formIds="getServerHealth"
reloadTopics="getServerHealth"
rowList="10,15,20"
rowNum="20"
rownumbers="false"
width="500"
loadonce="true"
>
<sjg:gridColumn name="name" index="name" title="Name" key="true" hidden="true" sortable="false"/>
<sjg:gridColumn name="label" index="label" title="Label" sortable="true"/>
<sjg:gridColumn name="health" index="health" title="Health" formatter="integer" sortable="true"/>
</sjg:grid>
<sjg:gridColumn name="name" index="name" title="Name" key="true" hidden="true" sortable="false"/>
<sjg:gridColumn name="label" index="label" title="Label" sortable="true"/>
<sjg:gridColumn name="health" index="health" title="Health" formatter="integer" sortable="true"/>
</sjg:grid>
<sjg:gridColumn name="name" key="true" index="name" title="Name" hidden="true" sortable="false"/>
<sjg:gridColumn name="label" index="label" title="Label" sortable="true"/>
<sjg:gridColumn name="health" index="health" title="Health" formatter="integer" sortable="true"/>
</sjg:grid>
Does anyone know if this type of conditioning is possible with jqgrid?
Well, it took a while, but after stumbling across this SO post today, I finally figured it out. I added an onCompleteTopics option to each grid, with a different formSubmission for each one. I then used javascript function to subscribe to those form submissions, and perform the logic. I utilized the event.originalEvent to get the information for retrieving row_ids that met my criteria for not wanting a subgrid, and the method proposed in the post took care of the rest! Kudos to that guy!