Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set struts2jquery Grid column names from JSON result of action
    primarykey
    data
    text
    <p>I have a <a href="http://en.wikipedia.org/wiki/Apache_Struts" rel="nofollow">Struts 2</a> action returning a JSON result.</p> <pre><code>{"columns":["coupon","CM","CM+1","CM+2","CM+3"],"couponList":[{"coupon":3.0,"CM":"88.2323","CM+1":"89.45","CM+2":"132.3128125","CM+3":"32.82"},{"coupon":3.5,"CM":"25","CM+1":"3125","CM+2":"333","CM+3":"5"}],"Caption":"30 Yr Fixed"} </code></pre> <p>I am able to populate the grid with the data. How do I populate the column names and caption using the "columns", "Caption" property returned in the JSON result?</p> <p>I am using the S2Jquery tag library. @JSP</p> <pre><code> &lt;%@taglib prefix="s" uri="/struts-tags"%&gt; &lt;%@taglib prefix="sj" uri="/struts-jquery-tags"%&gt; &lt;%@taglib prefix="sjg" uri="/struts-jquery-grid-tags"%&gt; &lt;link rel="stylesheet" href="../css/jqgrid_gcpm.css"&gt; &lt;link rel="stylesheet" href="../css/gcp.css"&gt; &lt;sj:head /&gt; &lt;s:url id="actionurl" action="testAction"&gt; &lt;s:set var="caption" value="Caption" /&gt; &lt;/s:url&gt; &lt;sjg:grid id="gridtable" caption="%{caption}" dataType="json" href="%{actionurl}" pager="false" gridModel="couponList" rowNum="-1" rownumbers="false" altRows="true" autowidth="true" resizable="true" shrinkToFit="true"&gt; &lt;sjg:gridColumn name="coupon" index="coupon" title="Coupon" sortable="false" width="30" /&gt; &lt;sjg:gridColumn name="CM" title="CM" sortable="false" formatter="htmlFormatter" /&gt; &lt;sjg:gridColumn name="CM+1" title="CM+1" sortable="false" formatter="htmlFormatter" /&gt; &lt;sjg:gridColumn name="CM+2" title="CM+2" sortable="false" formatter="htmlFormatter" /&gt; &lt;sjg:gridColumn name="CM+3" title="CM+3" sortable="false" formatter="htmlFormatter" /&gt; &lt;/sjg:grid&gt; &lt;script type="text/javascript"&gt; function htmlFormatter(cellValue, opts, rowObject) { if (cellValue == null) { return ''; } else { return cellValue; } } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload